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

int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> h(n);
    for ( int i = 0; i < n; i++ ) {
        cin >> h[i];
    }

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

    ll min_dif = 1000000001;
    for ( int i = 0; i <= n - k; i++ ) {
        min_dif = min ( min_dif, h[i+k-1] - h[i] );
    }

    cout << min_dif << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
    int x,y;
    for(int i=1;i<10001;i++){
        cin>>x>>y;
        if(x==0 && y==0){
            return 0;
        }else{
            if (y<x){
                cout<<y<<" "<<x<<endl;
            }else{
                cout<<x<<" "<<y<<endl;
            }

        }

    }
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void print() { cout << "\n"; }
template <class T, class... Args>
void print(const T &x, const Args &... args) { cout << x << " "; print(args...);}
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  sort(all(a));
  ll ans = 0;
  if (n % 2 == 0) {
    for (int i = 0; i < n/2; ++i) {
      if (i == n/2 - 1) ans -= a[i];
      else ans -= 2*a[i];
    }
    for (int i = n-1; i >= n/2; --i) {
      if (i == n/2) ans += a[i];
      else ans += 2*a[i];
    }
  }
  else {
    for (int i = 0; i < n/2+1; ++i) { //方法1
      if (i == n/2-1 || i == n/2) ans -= a[i];
      else ans -= 2*a[i];
    }
    for (int i = n/2+1; i < n; ++i) {
      ans += 2*a[i];
    }
    ll temp = 0;
    for (int i = 0; i < n/2; ++i) { //方法2
      temp -= 2*a[i];
    }
    for (int i = n/2; i < n; ++i) {
      if (i == n/2 || i == n/2+1) temp += a[i];
      else temp += 2*a[i];
    }
    chmax(ans,temp);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
import sys
from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 

h, w = load_list()
if h == 1 or w == 1:
    print(1)
    exit()
if h*w % 2 == 0:
    print(int(h*w/2))
else:
    print(int((h*w+1)/2))


Measured memory_bytes: 3316
#include <iostream>
using namespace std;
int main(){
	int x = -1,i = 1;
	while(x != 0){
		cin >> x;
		if(x == 0){
			break;
		}
		else {
			cout <<"Case "<<i<<": "<<x<<endl;
			i=i+1;
		}
	}
}


Measured memory_bytes: 3076
n =int(input())
H = list(map(int,input().split()))

c=0
cmax=0
for i in range(n-1):
    if H[i]>=H[i+1] :
        c+=1
    else:
        cmax = max(c,cmax)
        c=0
cmax = max(c,cmax)
print(cmax)


Measured memory_bytes: 20404
def f(i):
    global ans
    if i == 3:
        l = []
        for j in range(n):
            c = 0
            for k in range(3):
                c += t[k] * s[j][k]
            l.append(c)
        l.sort(reverse = True)
        d = 0
        for j in range(m):
            d += l[j]
        if d > ans:
            ans = d
        return
    f(i + 1)
    t[i] = 1
    f(i + 1)
    t[i] = -1

n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(n)]
t = [-1] * 3
ans = 0
f(0)
print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ull unsigned long long
#define mp make_pair
#define F first
#define S second
#define mod 1000000007


ll d[3005][3005];

int main()
{
    string s1,s2;
    cin >> s1 >> s2;
    
    for(int i=0;i<s1.size();i++) // initiating first row as zeros
        d[0][i] = 0;

    for(int i=0;i<s2.size();i++) // initiating first column as zero
        d[i][0] = 0;

    for(int i=1; i<=s1.size(); i++)
        for(int j=1; j<=s2.size(); j++)
            if(s1[i-1] == s2[j-1])
                d[i][j] = max(max(d[i-1][j-1]+1, d[i-1][j]),d[i][j-1]);
            else
                d[i][j] = max(d[i-1][j], d[i][j-1]);


    string str=""; //getting lcs of s1 and s2
    int i,j;
    i = s1.size();
    j = s2.size();

    while(i>0 && j>0) //traceback for the string
        if(d[i][j] == 1+d[i-1][j-1] && s1[i-1] == s2[j-1]) //if it was a match
            str += s1[i-1], i--, j--;
        else if(d[i][j-1] == d[i][j]) //if it was an insert
            j--;
        else if(d[i-1][j] == d[i][j]) //if it was a delete
            i--;


    reverse(str.begin(), str.end());
    cout << str << endl;

}

Measured memory_bytes: 70784
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <cstdint>
#include <istream>
#include <sstream>
#include <cctype>
#include <functional>
#include <iomanip>
#define rep(i,N) for(ll i=0;i<N;i++)
#define disp(a) cout << a << endl;
#define PI 3.1415926535897932384626433
//cout << fixed << setprecision(20) << ** << endl;
typedef long long ll;
using namespace std;
double deg2rad(double degree)
{
    return degree * PI / 180.0000000000;
}
int main()
{
	ll N,A,B,C=0;
	cin>>N>>A>>B;
	if(A+B-N>0)C=abs(A+B-N);
	cout<<min(A,B)<<" "<<C<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#include <complex>
#include <cassert>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

vector<pair<int,int> > primeFactor(int num){ //first->prime,second->pow{
	if(num==1){
		vector<pair<int,int> > r;
		r.push_back(make_pair(1,1));
		return r;
	}
	else{
		vector<pair<int,int> > r;
		for(int i=2;i*i<=num;i++){
			if(num%i==0){
				int p=0;
				while(num%i==0)
					num/=i,p++;
				r.push_back(make_pair(i,p));
			}
		}
		if(num!=1)
			r.push_back(make_pair(num,1));
		return r;
	}
}

int main(void){
    int N;
    GI(N);
    vector<int> factor(N+1,0);
    REP(i,N){
        auto f = primeFactor(i+1);
        for(auto j:f)
            factor[j.first] += j.second;
    }
    // REP(i,N)
        // printf("%d %d\n",i+1, factor[i+1]);
    int ans = 0;
    FOR(i, 2, N+1)
        if(factor[i]+1 >= 75)
            ans++;
    FOR(i, 2, N+1)
        FOR(j, 2, N+1){
            if(i != j){
                if(factor[i]+1 >= 3 && factor[j]+1 >= 25)
                    ans++;
                if(factor[i]+1 >= 5 && factor[j]+1 >= 15)
                    ans++;
            }
        }
    FOR(i, 2, N+1){
        FOR(j, 2, N+1){
            FOR(k, j+1, N+1){
                if(i != j && i != k && factor[i]+1 >= 3 && factor[j]+1 >= 5 && factor[k]+1 >= 5)
                    ans++;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#ALDS_3_B 16D8103010K Ko Okasaki

from collections import deque

n,q=map(int,input().split())
que=deque()
for i in range(n):
   name,time=input().split()
   time=int(time)
   que.append([name,time])

t=0

while len(que)>0:
    que_t=que.popleft()
    if que_t[1]>q:
        que_t[1]-=q
        t+=q
        que.append(que_t)
    else:
        t+=que_t[1]
        print(que_t[0],t)


Measured memory_bytes: 13276
#https://atcoder.jp/contests/abc136/tasks/abc136_b

import math

n = int(input())
a = int(math.log10(n))
cnt = 0
for i in range(a):
    if (i + 1) % 2 == 1:
        cnt += 10 ** (i + 1) - 10 ** i

if (a + 1) % 2 == 1:
    cnt += n - 10 ** a + 1

print(cnt)

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

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

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

template<int mod>
struct ModInt {
  int x;
  ModInt(): x(0) {}
  ModInt(int a) { x = a % mod; if (x < 0) x += mod; }
  ModInt &operator+=(ModInt that) { x = (x + that.x) % mod; return *this; }
  ModInt &operator-=(ModInt that) { x = (x + mod - that.x) % mod; return *this; }
  ModInt &operator*=(ModInt that) { x = (i64) x * that.x % mod; return *this; }
  ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
  ModInt operator-() { return ModInt(-this->x); }
  friend ostream& operator<<(ostream &os, ModInt m) { return os << m.x; }
  ModInt inverse() {
    int a = x, b = mod, u = 1, v = 0;
    while (b) { int t = a / b; a -= t * b; u -= t * v; swap(a, b); swap(u, v); }
    return ModInt(u);
  }
  #define op(o, p) ModInt operator o(ModInt that) { return ModInt(*this) p that; }
    op(+, +=) op(-, -=) op(*, *=) op(/, /=)
  #undef op
  #define op(o) bool operator o(ModInt that) const { return x o that.x; }
    op(==) op(!=) op(<) op(<=) op(>) op(>=)
  #undef op
};

using mint = ModInt<1000000007>;

void solve() {
  int n, m; cin >> n >> m;
  vi32 x(n), y(m); cin >> x >> y;
  mint ansx = 0, ansy = 0;
  reps(i, n - 1) {
    ansx += ((mint) n * i - (mint) i * i) * (x[i] - x[i - 1]);
  }
  reps(i, m - 1) {
    ansy += ((mint) m * i - (mint) i * i) * (y[i] - y[i - 1]);
  }
  cout << ansx * ansy << '\n';
}


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

using namespace std;

typedef long long ll;

const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T>
inline void chkmin(T&a, T b) { a = a < b ? a : b; }

int n, m;
int x[100010];
int y[100010];
int able[410];
bitset<410>b[410];

int main() {
#ifdef LOCAL
	FILE("");
#endif

	n = ri, m = ri;
	for(int i = 1; i <= m; i++) x[i] = ri, y[i] = ri;
	for(int i = 1; i <= n; i++) {
		b[i].set(i);
		for(int j = m; j >= 1; j--) {
			int X = b[i][x[j]], Y = b[i][y[j]];
			if(X && Y) { able[i] = 1; break; }
			else if(X) b[i].set(y[j]);
			else if(Y) b[i].set(x[j]);
		}
	} int res = 0;
	for(int i = 1; i <= n; i++) if(!able[i])
		for(int j = i + 1; j <= n; j++) if(!able[j])
			res += !(b[i] & b[j]).any();
	cout << res << endl;
	return 0;
}

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

bool is_same_image(vector<string> &image_a, vector<string> &image_b, int a_h, int a_w)
{
  for (int b_h = 0; b_h < image_b.size(); b_h++)
  {
    for (int b_w = 0; b_w < image_b.size(); b_w++)
    {
      if (image_a.at(a_h + b_h).at(a_w + b_w) != image_b.at(b_h).at(b_w))
      {
        return false;
      }
    }
  }
  return true;
}

int main()
{
  int len_a, len_b;
  cin >> len_a >> len_b;

  vector<string> image_a(len_a);
  vector<string> image_b(len_b);

  for (int i = 0; i < len_a; i++)
  {
    cin >> image_a.at(i);
  }
  for (int i = 0; i < len_b; i++)
  {
    cin >> image_b.at(i);
  }

  for (int h = 0; h < len_a - len_b + 1; h++)
  {
    for (int w = 0; w < len_a - len_b + 1; w++)
    {
      if (is_same_image(image_a, image_b, h, w))
      {
        cout << "Yes" << endl;
        exit(0);
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>

int n;
int r, b;
char s[111111];

int main(){
	scanf("%d", &n);
	scanf("%s", s + 1);
	for(int i = 1; i <= n; i++)
		(s[i] == 'R') ? (r++) : (b++);
	if(r > b) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <iostream>
#include <set>

using namespace std;

long long gcd(long long a, long long b) {
    if (a < b) return gcd(b, a);

    if (a % b == 0) return b;

    return gcd(b, a % b);
}

int main() {
    int queries;

    scanf("%d", &queries);

    for (int query = 0; query < queries; ++query) {
        long long firstStock, dailyPurchase, stockCond, stockCount;

        scanf("%lld%lld%lld%lld", &firstStock, &dailyPurchase, &stockCond, &stockCount);

        if (dailyPurchase > stockCount) {
            printf("No\n");
            continue;
        }

        if (firstStock < dailyPurchase) {
            printf("No\n");
            continue;
        }

        long long x = gcd(dailyPurchase, stockCount);

        if (x == 0) {
            printf("Yes\n");
            continue;
        }

        long long stockMin = firstStock;

        stockMin -= x * ((firstStock - stockCond - 1) / x);

        stockMin -= dailyPurchase;

        if (stockMin < 0) {
            printf("No\n");
        } else {
            printf("Yes\n");
        }
    }
    return 0;
}

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

int main() {
  int X, Y;
  cin >> X >> Y;
  
  int S = 0;
  int a[4] = {0, 300000, 200000, 100000};
  
  if (X == 1 && Y == 1) {
    S = 1000000;
  } else if (X <= 3||Y <= 3) {
    if (X <= 3) S += a[X];
  	if (Y <= 3) S += a[Y];
  }
  
  cout << S << endl;
}


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

using namespace std;

// 目的の値 key の index を返すようにする (ない場合は -1)
// https://qiita.com/drken/items/97e37dd6143e33a64c8c
int binary_search(int key, vector<int>& a) {
    int left = 0, right = (int)a.size() - 1; // 配列 a の左端と右端
    while (right >= left) {
        int mid = left + (right - left) / 2; // 区間の真ん中
        if (a[mid] == key) return mid;
        else if (a[mid] > key) right = mid - 1;
        else if (a[mid] < key) left = mid + 1;
    }
    return -1;
}

int main(){
    int n,m; cin >> n >> m;
    int p, y;
    set<int> st{};
    vector<vector<int>> c;
    c = vector<vector<int>>(n + 1);
    vector<pair<int,int>> list;
    for(int i = 0; i < m; i++){
        cin >> p >> y;
        pair<int,int> pp;
        st.insert(p);
        c[p].push_back(y);
        pp.first = p;
        pp.second = y;
        list.push_back(pp);
    }
    
    for(auto itr = st.begin(); itr != st.end(); ++itr) {
        sort(c[*itr].begin(), c[*itr].end());
    }

    for(int i = 0 ;i < m; i++){
        int size = c[list[i].first].size();
        printf("%06d",list[i].first);
        int j = binary_search(list[i].second, c[list[i].first]);
        printf("%06d",j+1);
        cout << "\n";
    }
    return 0;
}


Measured memory_bytes: 12404
#include <bits/stdc++.h>
using namespace std;
int n, m;
int ch, cw;
int dh, dw;
vector<vector<bool>> matrix, used;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
bool is_valid(int x, int y){
	return (0 <= x && x < n) && (0 <= y && y < m) && !used[x][y] && matrix[x][y];
}
int main(){
	cin >> n >> m >> ch >> cw >> dh >> dw;
	ch--, cw--, dh--, dw--;
	matrix = used = vector<vector<bool>>(n, vector<bool>(m));
	for(int i = 0; i < n; i++){
		string s; cin >> s;
		for(int j = 0; j < m; j++) matrix[i][j] = (s[j]=='.');
	}
	deque<pair<pair<int, int>, int>> q;
	q.push_front({{ch, cw}, 0});
	while(!q.empty()){
		pair<pair<int, int>, int> x = q.front();
		q.pop_front();
		pair<int, int> position = x.first;
		if(used[position.first][position.second]) continue;
		used[position.first][position.second] = true;
		if(position.first == dh && position.second == dw){
			cout << x.second << '\n'; return 0;
		}
		for(int i = 0; i < 4; i++){
			int newx = position.first+dx[i];
			int newy = position.second+dy[i];
			if(is_valid(newx, newy)) q.push_front({{newx, newy}, x.second});
		}
		for(int i = -2; i <= 2; i++){
			for(int j = -2; j <= 2; j++){
				int newx = position.first+i;
				int newy = position.second+j;
				if(is_valid(newx, newy)) q.push_back({{newx, newy}, x.second+1});
			}
		}
	}
	cout << "-1\n";
	return 0;
}


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


void mark(int mp[10][10],int y,int x){
  int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
  for(int i=0;i<4;i++) {
    int nx=x+dx[i],ny=y+dy[i];
    if(nx<0||ny<0||nx>=10||ny>=10)continue;
    mp[ny][nx]=!mp[ny][nx];
  }
  mp[y][x]=!mp[y][x];
}

bool check(int mp[10][10]){
  for(int i=0;i<10;i++)
    for(int j=0;j<10;j++)if(mp[i][j])return 0;
  return 1;
}

void copy(int a[10][10],int b[10][10]){
  for(int i=0;i<10;i++)for(int j=0;j<10;j++)a[i][j]=b[i][j];
}

int main(){
  int q;
  cin>>q;
  while(q--){
    int mp[10][10],b[10][10];
    for(int i=0;i<10;i++)for(int j=0;j<10;j++)cin>>mp[i][j];

    copy(b,mp);
    int ans[10][10]={};
    for(int i=0;!check(mp);i++){
      copy(mp,b),copy(b,mp);
      for(int j=0;j<10;j++)if((ans[0][j]=((i>>j)%2)))mark(mp,0,j);
      for(int j=1;j<10;j++)
	for(int k=0;k<10;k++)
	  if((ans[j][k]=mp[j-1][k]))mark(mp,j,k);
    }

    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
	if(j) cout <<" ";
	cout << ans[i][j];
      }
      cout <<endl;
    }
  }
  return 0;
}

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

import math
import sys
from collections import deque

class SegmentTree(object):

    def __init__(self,a,default):
        real_size=len(a)
        self.elem_size=elem_size=1<<math.ceil(math.log2(real_size))
        self.tree=tree=[default]*(elem_size*2-1)
        tree[elem_size:elem_size+real_size]=a
        self.default=default

        for i in range(elem_size-2,-1,-1): #ここで初期のsegtreeの構築
            l,r=tree[2*i+1],tree[2*i+2]
            tree[i]=l if l<r else r
    def get_value(self,x,y):#[x,y)で注意
        stack=deque([(x,y,0,0,self.elem_size)])
        tree=self.tree
        ans=self.default
        while(stack):
            x,y,k,l,r=stack.pop()
            if r<=x or y<=l:
                continue
            if x<=l and r<=y:
                ans=min(ans,tree[k])
            else:
                stack.append((x,y,k*2+1,l,(l+r)//2))
                stack.append((x,y,k*2+2,(l+r)//2,r))
        return ans
    def update(self,i,x):
        i+=self.elem_size-1
        tree=self.tree
        tree[i]=x
        while(i>0):
            i=(i-1)//2
            tree[i]=min(tree[i*2+1],tree[i*2+2])


n,q=map(int,input().split())
tree=SegmentTree([2**31-1]*n,2**31-1)
for i in range(q):
    com,x,y=map(int,input().split())
    if com==0:
        tree.update(x,y)
    else:
        print(tree.get_value(x,y+1))



Measured memory_bytes: 9880
a = 100
l = [0]*a
t = 1
for x in xrange(a):
	while t%2 == 0:
		t = t/2
		l[x] += 1
	t = x+2
a = int(raw_input())
ma = 0
mi = 1
for x in range(a):
	if l[x] > ma:
		ma = l[x]
		mi = x
if a == 1:
	print(1)
else:
	print(mi+1)

Measured memory_bytes: 2568
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

#define rep0(i, n) for (i = 0; i < n; i++)
#define rep(s, i, n) for (i = s; i < n; i++)
using namespace std;

int N, Q, a[100001];
long long ans;

int main()
{
    int i, j, b, c;
    cin >> N;
    rep0(i, N)
    {
        cin >> j;
        ans += j;
        a[j]++;
    }
    cin >> Q;

    rep0(i, Q)
    {
        cin >> b >> c;
        ans += (c - b) * a[b];
        a[c] += a[b];
        a[b] = 0;
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3932
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;
 
int main(){
  using namespace std;
  string s;
  cin>>s;
  int n;
  n = s.size();
  int now = 1;
  deque<char> ans;
  REP(i, n){
    ans.push_back(s[i]);
  }
  int q;
  cin>>q;
  REP(i, q){
    int t;
    cin>>t;
    if(t == 1){
      if(now == 1){
        now = -1;
      }else{
        now = 1;
      }
    }else{
      int f;
      char c;
      cin>>f>>c;
      if(now == 1){
        if(f == 1){
          ans.push_front(c);
        }else{
          ans.push_back(c);
        }
      }else{
        if(f == 1){
          ans.push_back(c);
        }else{
          ans.push_front(c);
        }
      }
    }
  }
  if(now == 1){
    for(char c: ans){
      cout<<c;
    }
    cout<<endl;
  }else{
    string str = "";
    for(char c: ans){
      str += c;
    }
    reverse(ALL(str));
    cout<<str<<endl;
  }
  return 0;
}


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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

typedef unsigned long long ull;
const int base = 131;
const int maxn = 5e3+5;
char A[maxn]; ull sum[maxn], pw[maxn];

ull hash_(const int i, const int j)
{
    return sum[j]-sum[i-1]*pw[j-i+1];
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0); cout.precision(10); cout << fixed;
    int n; 
    while (cin >> n >> &A[1]) {
        pw[0] = 1;
        FOR(i,1,n+1) {
            sum[i] = sum[i-1]*base + A[i];
            pw[i] = pw[i-1]*base;
        }
        int lo = 0, hi = n/2;
        while (lo < hi) {
            const int mid = lo + (hi-lo+1)/2;
            map<ull,int> pos;
            FOR(i,1,n+1) if (i+mid <= n+1) {
                const int j = i+mid-1;
                const ull h = hash_(i,j);
                pos[h] = i;
            }
            bool P = false;
            FOR(i,1,n+1) if (i+mid <= n+1) {
                const int j = i+mid-1;
                const ull h = hash_(i,j);
                if (pos[h] > j)
                    P = true;
            }
            if (P)
                lo = mid;
            else
                hi = mid-1;
        }
        cout << hi << endl;
    }
    return 0;
}


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

int main(){
    long L, R;
    cin >> L >> R;
    int min = 2019;
    for(long i=L, counti=0; i<R; i++, counti++){
        if(counti > 2019) break;
        for(long j=i+1, countj=0; j<=R; j++, countj++){
            if(countj > 2019) break;
            int num = (i*j)%2019;
            if(min > num) min = num;
        }
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
int main(void){
	char data[100];
	char answer[100];
	scanf("%s",data);
	int len=strlen(data);
	scanf("%s",answer);
	for(int i=0;i<len;i++){
		bool check=true;
		for(int j=0;j<len;j++){
			if(answer[j] != data[(i+j)%len]){
				check=false;
				break;
			}
		}
		if(check){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int ans=0, s=S.size();
  
  for(int i=0; i<(s/2); i++){
    if(S.at(i)==S.at(s-1-i)) continue;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().strip().split()))
q = int(input())

import collections

result = sum(a)
counter = collections.Counter(a)

for j in range(q):
  b,c = list(map(int,input().strip().split()))
  if c in counter:
    counter[c] += counter[b]
  else:
    counter[c] = counter[b]
  result += (c-b) * counter[b]
  counter[b] = 0
  print(result)

Measured memory_bytes: 89964
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
    N = int(readline())
    A = [0] + [int(i) for i in readline().split()]
    table = [0 for _ in range(N+1)] 
    for i in [int(i) for i in range(1, N+1)][::-1]:
        table[i] = (sum(table[::i])+A[i])%2
    print(sum(table))
    for i in range(N):
        if table[i+1]:
            print(i+1, end=' ')
if __name__ == '__main__':
    main()


Measured memory_bytes: 15536
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Test int T;cin>>T;while(T--)
#define ls lower_bound
#define up upper_bound
#define bs binary_search
#define S second
#define F first
#define vi vector<int>  
#define pii pair<int,int>
#define vpi vector<pii>
#define vvi vector<vi>
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define m_n(v) *min_element(all(v))
#define m_x(v) *max_element(all(v))
#define ___(a) for(auto &i:a) cin>>i
#define __(a)  for(auto i:a) cout<<i<<" "
#define nl cout<<"\n";
#define momo(k) memset(k,0,sizof(k))
#define momi(k) memset(k,-1,sizeof(k))
/* 
#include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>indexed_set;
*/
int power(int x, int y,int mod){
    int res = 1;
    while (y)
    {
        if (y & 1)
        res = (res*x)%mod;
        y = y>>1;
        x = (x*x)%mod;
    }
    return res;
}
int modInverse(int a, int m){
    int m0 = m;
    int y = 0, x = 1;

    if (m == 1)
      return 0;

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

    return x;
}
int binomial(int n,int k){
    int res = 1;
    if ( k > n - k )
        k = n - k;

    for (int i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }

    return res;
}

// vector<int> prime;
// void sieve(){
//     bool arr[300000]={0};
//     prime.pb(2);
//     for(int i=3;i<300000;i+=2){
//         if(arr[i])continue;
//         for(int j=i*i;j<300000;j+=i) arr[j]=1;
//         prime.pb(i);
//     }
// }
// const int N=1e18+2;
const int mod = 1e9+7;
const int N= 1e5+9;
int dp[N] = {0};

int32_t main() {
    IOS;
    for(int i=0;i<N;i++) dp[i] = mod;
    dp[0] = 0;
    int n,W;
    cin>>n>>W;
    int w,v;
    int sum = 0;
    for(int i=0;i<n;i++){
        cin>>w>>v;
        sum += v;
        for(int j=sum;j>=v;j--){
            dp[j] = min(dp[j],w+dp[j-v]);
        }
    }
    for(int i=N-1;i>=0;i--){
        if(dp[i] <= W){
            cout<<i;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 4392
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int h500=0;
  int h50=0;
  
  int temp=n%500;
  n=n/500;
  h500=1000*n;
  //cout<<n;
  int temp2=temp/5;
   h50=5*temp2;
  
  cout<<h50+h500;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9


int main(){
    while(1){
	int n;
	cin>>n;
	if(n==0)break;
	stack<mp> s1;
	int hm=0,rm=0;
	for(int i=0;i<n;i++){
		int h,r;
		cin>>h>>r;
		s1.push(mp(h,r) );
		hm = max(hm,h);
		rm = max(rm,r);
	}
	int m;
	cin>>m;
	stack<mp> s2;
	for(int i=0;i<m;i++){
		int h,r;
		cin>>h>>r;
		s2.push(mp(h,r) );
		hm = max(hm,h);
		rm = max(rm,r);
	}
	vector<vector<int> > dp(hm+2 , vector<int>(rm+2,0) );
	while(!s1.empty()){
		mp now = s1.top();
		s1.pop();
		dp[now.first][now.second] = 1;
	}
	while(!s2.empty()){
		mp now = s2.top();
		s2.pop();
		dp[now.first][now.second] = 1;
	}
	for(int i=hm;i>=0;i--){
		for(int j=rm;j>=0;j--){
		    if(dp[i][j] == 1) dp[i][j] = dp[i+1][j+1] + 1;
			dp[i][j] =  max(dp[i][j], max(dp[i+1][j],dp[i][j+1]) ) ;
		}
	}
	cout<<dp[0][0]<<endl;
	}

	return 0;
}



Measured memory_bytes: 5516
import java.util.HashMap;
import java.util.Scanner;

/*
説明
*/
public class Main {
    public static void main(String[] args){

        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int a[] = new int[n];

        HashMap<Integer, Long> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            a[i] = s.nextInt();

            if (!map.containsKey(a[i])) {
                map.put(a[i], (long)1);
            } else {
                map.put(a[i], map.get(a[i])+1);
            }
        }

        long all = 0;
        // 全通りを求める
        for (int key :map.keySet()) {
            all += map.get(key) * (map.get(key) - 1) / 2;
        }

        for (int i = 0; i < n; i++) {
            long tmp = map.get(a[i]);
            System.out.println(all - (tmp - 1));
        }
    }
}

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

#define ll long long

using namespace std;

int main(){
    int n,sum=0;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            sum=sum+(a[i]*a[j]);
        }
    }
    cout<<sum<<endl;
}


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

int main() {
    int64_t N;
    cin >> N;
    vector<int64_t> A(N);
    for (int64_t& a : A) {
        cin >> a;
    }

    int64_t ans = 0;
    constexpr int64_t MOD = 1e9 + 7;

    int64_t sum = A[0];
    for (int64_t i = 1; i < N; i++) {
        (ans += A[i] * sum) %= MOD;
        (sum += A[i]) %= MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4784
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
const int N = 2e5+5;
const int M = 1e9+7;
#define pi acos(-1)
#define INF 1e8
#define INM INT_MIN
#define pb(a)  push_back(a)
#define mk(a,b) make_pair(a,b)
#define dbg(x) cout << "now this num is " << x << endl;
#define met0(axx) memset(axx,0,sizeof(axx));
#define metf(axx) memset(axx,-1,sizeof(axx));
#define sd(ax) scanf("%d",&ax)
#define sld(ax) scanf("%lld",&ax)
#define sldd(ax,bx) scanf("%lld %lld",&ax,&bx)
#define sdd(ax,bx) scanf("%d %d",&ax,&bx)
#define sddd(ax,bx,cx) scanf("%d %d %d",&ax,&bx,&cx)
#define sfd(ax) scanf("%lf",&ax)
#define sfdd(ax,bx) scanf("%lf %lf",&ax,&bx)
#define pr(a) printf("%d\n",a)
#define plr(a) printf("%lld\n",a)
/*
考虑容斥的思想.
题目说要我们统计经过该点的边数,那么我们可以计算出不经过该点的边数,然后用总的边数减去.
对于n个点,能形成的边的数目是C(n,2),(即n*(n-1)/2),n个点选2个点组成路径.
但是对于这题的简单路径比较特殊(1-1)(2-2)这种也算,所以最终的点数是C(n,2)+n;//加上自己到自己的边数
那么我们以颜色来dfs.
如何计算不经过的路径：
很明显,不经过的路径肯定是处于同一颜色的同一侧的节点组成的路径.
对于一种颜色,在这种颜色和下一个和它一样的颜色的节点处,中间的节点之间组成的边,肯定都是不经过的.
那么对于一种颜色,肯定是减去多个连通块之间的路径数.
定义ssize[i]为以i为根的子树的总节点数(包括i).sum[i]为以颜色i为根的子树的大小.
假设当前节点颜色为c。
我们需要找到下面的和它相连的颜色为c的点。
当我们找到后用这条边上的子节点的size-相邻的下面的以c为颜色的点的size(即记录用的sum).
这样就知道了中间有多少个数.
如何更新这个sum。
因为可能会有多条边遍历之后的后效性。
所以我们用一个变量记录开始遍历该子节点时的sum值,然后用遍历结束后的sum值去减就知道了下面c的位置的子节点数(即sum[c]).
化为图的思想:(这里图的数字表示颜色.)  
*/
int ssize[N],sum[N],col[N];
LL f[N];
vector<int> G[N];
LL cal(LL x)
{
	return x*(x+1)/2;
}
void dfs(int u, int fa) {
    int c = col[u],save = sum[c];
    ssize[u] = 1;
    for(auto y : G[u]) 
	{
        if(y == fa) continue;
        int ma = sum[c];//记录遍历该条边之前的sum[c].
        dfs(y, u);
		ssize[u] += ssize[y];
        int x = sum[c]-ma;//遍历之后的差
        f[c] += cal(ssize[y]-x);
    }
    sum[c] = save + ssize[u];
}
int main()
{
	int n;sd(n);
	for(int i=1;i<=n;++i) sd(col[i]);
	for(int i=1;i<n;++i)
	{
		int x,y;sdd(x,y);
		G[x].pb(y),G[y].pb(x);
	}
	LL all = cal(n);
	dfs(1,0);
	for(int i=1;i<=n;++i)
	{
		int x = n-sum[i];//从根到第一个i颜色处空出来的部分的连通块的和.
		f[i] += cal(x);
		plr(all-f[i]);
	}
	//system("pause");
	return 0;
}

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

int main(){
  int N;
  int a[200000];
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> a[i];
  }
  int count = 1;
  int ans = 0;
  for(int i=0;i<N;i++){
    if(a[i] == count){
      count++;
      ans++;
    }
  }
  if(ans == 0){
    cout << -1;
  }else{
    cout << (N-ans);
  }
  return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll k,a,b; cin>>k>>a>>b;
  ll ans=min(k,a-1)+1;
  k-=ans-1;
  
  if(k){
    // cout<<ans<<endl;
    if(a+1<b){
      ans+=k/2*(b-a)+k%2;
      // cout<<ans<<endl;
    }else{
      ans+=k;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int a[100005],n;
signed main(){
	cin >> n;
	for(int i = 1 ; i <= n ; i ++) cin >> a[i];
	sort(a + 1, a + n + 1);
	int ans = 0;
	if(n % 2 == 1){
		cout << 0;
		return 0;
	}
	else{
		cout << a[(n/2) + 1] - a[(n/2)];
	}
}

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

int main(void){
    int w,h,n;
    cin>>w>>h>>n;
    int lx=0,rx=w,ly=0,ry=h;
    rep(i,n){
        int x,y,a;
        cin>>x>>y>>a;
        if(a==1) lx = max(lx,x);
        if(a==2) rx = min(rx,x);
        if(a==3) ly = max(ly,y);
        if(a==4) ry = min(ry,y);
    }
    int res;
    if(lx>=rx || ly>=ry) res = 0;
    else res = (rx-lx)*(ry-ly);
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] cnt = new int[n];
		for (int i = 0; i < n; i++) {
			cnt[Integer.parseInt(sa[i])]++;
		}
		br.close();

		if (!"0".equals(sa[0]) || cnt[0] != 1) {
			System.out.println(0);
			return;
		}

		long ans = 1;
		int idx = n;
		for (int i = 1; i < n; i++) {
			if (cnt[i] > 0) {
				ans *= power(cnt[i - 1], cnt[i]);
				ans %= 998244353;
			} else {
				idx = i;
				break;
			}
		}
		for (int i = idx + 1; i < n; i++) {
			if (cnt[i] > 0) {
				System.out.println(0);
				return;
			}
		}
		System.out.println(ans);
	}

	static long power(long x, long n) {
		if (n == 0) {
			return 1;
		}
		int mod = 998244353;
		long val = power(x, n / 2);
		val = val * val % mod;
		if (n % 2 == 1) {
			val = val * x % mod;
		}
		return val;
	}
}


Measured memory_bytes: 36188
#include<iostream>

using namespace std;

int main(){
  int N;
  cin >> N;
  int V[N], C[N];
  for(int i=0; i<N; i++) cin >> V[i];
  for(int i=0; i<N; i++) cin >> C[i];

  int ans = 0;
  int add = 0;
  for(int i=0; i<N; i++){
    add = V[i] - C[i];
    if(add > 0) ans += add;
  }

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


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

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

using namespace std;
using ll = long long;

int main(void) {
  double l;
  cin >> l;
  l = (l * l * l) / 27.0;
  printf("%.12f\n", l);
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
const int INF = (1LL<<30);
const ll LLINF = (1LL<<60);
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;
#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

VL xx, x, unzipx(100010), yy, y, unzipy(100010), zz, z, unzipz(100010);
unordered_map<int, int> zipx, zipy, zipz;
void compress() {
  x = xx;
  sort(ALL(xx));
  xx.erase(unique(ALL(xx)), xx.end());
  REP(i, xx.size()) {zipx[xx[i]] = i; unzipx[i] = xx[i];}
  REP(i, x.size()) x[i] = zipx[x[i]];
  y = yy;
  sort(ALL(yy));
  yy.erase(unique(ALL(yy)), yy.end());
  REP(i, yy.size()) {zipy[yy[i]] = i; unzipy[i] = yy[i];}
  REP(i, y.size()) y[i] = zipy[y[i]];
  z = zz;
  sort(ALL(zz));
  zz.erase(unique(ALL(zz)), zz.end());
  REP(i, zz.size()) {zipz[zz[i]] = i; unzipz[i] = zz[i];}
  REP(i, z.size()) z[i] = zipz[z[i]];
}

int dp[105][105][105];
int sx[55], sy[55], sd[55], gx[55], gy[55], gd[55];
signed main(void)
{
  int n, K;
  cin >> n >> K;
  REP(i, n) {
    cin >> sx[i] >> sy[i] >> sd[i] >> gx[i] >> gy[i] >> gd[i];
    xx.PB(sx[i]); xx.PB(gx[i]);
    yy.PB(sy[i]); yy.PB(gy[i]);
    zz.PB(sd[i]); zz.PB(gd[i]);
  }
  compress();

  // cout << "a" << endl;
  // REP(i, n) {
  //   cout << zipx[sx[i]] << " " << zipy[sy[i]] << " " << zipz[sd[i]] << " " << zipx[gx[i]] << " " << zipy[gy[i]] << " " << zipz[gd[i]] << endl;
  // }

  REP(i, n) {
    // cout << i << endl;
    // cout << zipx[sx[i]] << " " << zipy[sy[i]] << " " << zipz[sd[i]] << " " << zipx[gx[i]] << " " << zipy[gy[i]] << " " << zipz[gd[i]] << endl;
    FOR(z, zipz[sd[i]], zipz[gd[i]]) FOR(y, zipy[sy[i]], zipy[gy[i]]) FOR(x, zipx[sx[i]], zipx[gx[i]]) {
      dp[z][y][x]++;
    }
    // REP(ii, z.size()) {
    //   cout << "z:" << ii << endl;
    //   REP(j, y.size()) {
    //     REP(k, x.size()) {
    //       cout << dp[ii][j][k] << " ";
    //     }
    //     cout << endl;
    //   }
    // }
    // cout << endl;
  }

  // cout << "b" << endl;

  ll ret = 0;
  REP(i, z.size()) REP(j, y.size()) REP(k, x.size()) {
    if(dp[i][j][k] >= K) {
      ret += (unzipz[i+1]-unzipz[i])*(unzipy[j+1]-unzipy[j])*(unzipx[k+1]-unzipx[k]);
    }
  }

  cout << ret << endl;

  return 0;
}

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

namespace AtCoder_Core
{
    class Program
    {
        static void Main(string[] args)
        {
            int X = int.Parse(Console.ReadLine());
            int c5 = 0;
            int c500 = 0;
            while (X - 500 >= 0)
            {
                c500++;
                X -= 500;
            }
            while (X - 5 >= 0)
            {
                c5++;
                X -= 5;
            }
            Console.WriteLine((c500*1000)+(c5*5));
        }
    }
}


Measured memory_bytes: 11092
n, k = map(int, input().split())
max_multiple_count = 0
min_multiple_count = 0
max_multiple = 1
min_multiple = min(n, k-1)
while max_multiple < k:
    max_multiple_count += 1
    max_multiple *= 2

if n - k >= 0:
    ans = (n - k + 1)/n
else:
    ans = 0
for i in range(1, min(n+1, k)):
      I = i
      for j in range(1, max_multiple_count+1):
            I *= 2
            if I >= k:
                ans += (1/n) * ((1/2)**j)
                break

print(ans)

Measured memory_bytes: 39152
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int x;
        if(1 <= a && a <=10000 && 1 <= b && b <= 10000 && 1 <=c && c <= 10000){
            if(a > b){
                x = a;
                a = b;
                b = x;
            }
            if(b > c){
                x = b;
                b = c;
                c = x;
            }
            if(a > b){
                x = a;
                a = b;
                b = x;
            }
            System.out.println(a +" "+ b +" "+ c);

        }
    }
}



Measured memory_bytes: 26116
N = int(input())
List = [list(map(int,input().split(" "))) for i in range(N)]
List.sort(key=lambda x: x[1])

time = 0
for i in range(N):
  time += List[i][0]
  if time > List[i][1]:
    print("No")
    break
else:
  print("Yes")

Measured memory_bytes: 53728
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // long long64_t, long long*_t
#include <cstdio> // prlong longf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
using namespace std;
int main(){
  int n;
  cin >> n;
  if(n%2==0) cout << 0.5 << endl;
  else{
    double k,x;
    x=(n+1)/(2.00000*n);
    cout << x << endl;
  }
  
}


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

int maxt(int x){
    return (x+9)/10 * 10;
}
int maxr(int x){
    return maxt(x)-x;
} 


int main(){

    int a,b,c,d,e;
    
    cin >> a >> b >> c >> d >> e;

    int r; 

    r = maxt(a)+maxt(b)+maxt(c)+maxt(d)+maxt(e);
    r -= max({maxr(a),maxr(b),maxr(c),maxr(d),maxr(e)});

    cout << r << endl;

}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int n,f0,f1,f2=0;
    scanf("%d",&n);
    if(n==0||n==1) f2 = 1;
    else
    {
        f0 = 1;
        f1 = 1;
        for(int i=2;i<=n;i++)
        {
            f2 = f0 + f1;
            f0 = f1;
            f1 = f2;
        }
    }
    printf("%d\n",f2);
    return 0;
}


Measured memory_bytes: 2044