akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = ReadLine().Select(s => s - '0').ToArray();
            var ans = Head(N);
            //頭が0の時の値
            for (var i = 0; i < N.Length; ++i)
                ans += Calc(i, 0);
            WriteLine(ans);
            //Out.Flush();
        }
        static long  Head(int[] N)
        {
            var used = new bool[10];
            var is753 = new bool[10];
            is753[7] = true;is753[5] = true;is753[3] = true;
            var keta = N.Length;
            var ret = 0L;
            for (var i = 0; i < keta; ++i)
            {
                var h = N[i];
                if (is753[h])
                {
                    ret += NotUpper(h - 1, keta - i, used);
                    used[h] = true;
                    if (i == keta - 1 && used.Count(u => u) == 3) ++ret;
                    continue;
                }
                else
                {
                    ret += NotUpper(h, keta - i, used);
                    break;
                }
            }
            return ret;
        }
        static long NotUpper(long h, long keta, bool[] used753)
        {
            var ans = 0L;
            var used753num = used753.Count(u => u);
            if (3 <= h)
            {
                var num3 = used753num;
                if (!used753[3]) ++num3;
                ans = Calc(keta - 1, num3);
            }
            if (5 <= h)
            {
                var num5 = used753num;
                if (!used753[5]) ++num5;
                ans += Calc(keta - 1, num5);
            }
            if (7 <= h)
            {
                var num7 = used753num;
                if (!used753[7]) ++num7;
                ans += Calc(keta - 1, num7);
            }
            return ans;
        }
        static long Calc(long nokoriKeta, long used753)
        {
            if (nokoriKeta == 0)
            {
                if (3 == used753)
                    return 1;
                else
                    return 0;
            }
            if (used753 == 0)
                return (long)(Pow(3, nokoriKeta) - 1 * 3 - (Pow(2, nokoriKeta) - 2) * 3);
            if (used753 == 1)
                return (long)(Pow(3, nokoriKeta) - 1 * 3 - (Pow(2, nokoriKeta) - 2) * 2);
            if (used753 == 2)
                return (long)(Pow(3, nokoriKeta) - 1 * 2 - (Pow(2, nokoriKeta) - 2) * 1);
            return (long)(Pow(3, nokoriKeta));
        }
    }
}

Measured memory_bytes: 13396
#include<stdio.h>
#include<math.h>

int main (void)
{


    int sets;

    scanf("%d",&sets);


    int a[1000][3];
    int b[1000][3] = {};

    int i;

    for(i = 0; i < sets; i++){
        scanf("%d%d%d",&a[i][0] ,&a[i][1] ,&a[i][2]);

        if((a[i][0] > a[i][1]) && (a[i][0] > a[i][2])){
            b[i][0] = 1;
        }else if((a[i][1] > a[i][0]) && (a[i][1] > a[i][2])){
            b[i][1] = 1;
        }else if((a[i][2] > a[i][0]) && (a[i][2] > a[i][1])){
            b[i][2] = 1;
        }

    }

    for(i = 0; i < sets; i++){

        //printf("%d%d%d",b[i][0],b[i][1],b[i][2]);

        if((b[i][0] == 1) && (a[i][0] * a[i][0] == a[i][1] * a[i][1] + a[i][2] * a[i][2]))
            printf("YES\n");
        else if((b[i][1] == 1) && (a[i][1] * a[i][1] == a[i][0] * a[i][0] + a[i][2] * a[i][2]))
            printf("YES\n");
        else if((b[i][2] == 1) && (a[i][2] * a[i][2] == a[i][0] * a[i][0] + a[i][1] * a[i][1]))
            printf("YES\n");
        else
            printf("NO\n");
    }


    return 0;
}

Measured memory_bytes: 612
const input = require('fs').readFileSync('/dev/stdin', 'UTF-8');

const smallLargeOrEqual = input => {
  const [a, b] = input.split(' ').map(val => Number(val));
  if (a === b) {
    console.log('a == b');
  } else if (a > b) {
    console.log('a > b');
  } else if (a < b) {
    console.log('a < b');
  }
};

smallLargeOrEqual(input);



Measured memory_bytes: 15132
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}";
  return o;
}


int main() {
  ll N,M;
  cin >> N >> M;
  ll cnt=0,add=0;
  add = min(N,M/2);
  M-=2*add;
  cnt+=add;
  add = M/4;
  cnt+=add;
  cout << cnt << endl;
}

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

uint64_t Lucas(int &N){
  uint64_t x0=2,x1=1,x2;
  if(N==1)return 1;
  for(int i=0;i<N-1;i++){
    x2=x0+x1;
    x0=x1;
    x1=x2;
  }
  return x2;
}
int main(){
  int N;
  cin>>N;
  cout<<Lucas(N)<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
    int k,n;
    cin>>k>>n;
    vector<int> a(n,0);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(full(a));
    int ans=0;
    for(int i=0;i<n;i++){
        if(i<n-1)
            ans=max(ans,a[i+1]-a[i]);
        else
            ans=max(ans,k-a[i]+a[0]);
    }
    cout<<k-ans<<"\n";
}

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

    solve();
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    int a,b,result;
    cin >> a >> b;
    
    if(a>=6 && a<=12){
        result = b/2;
    } else if(a<=5){
        result=0;
    } else result =b;
    cout << result << endl;
    
    return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
//#include <bits/stdc++.h>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAX 9223372036854775800

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

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



int main() {
  ll N,M,C;
  cin >> N>>M>>C;
  ll B[M];
  ll A[N][M];
  ll ans=0;
  FOR(i,0,M-1){
    cin>>B[i];
  }

  FOR(i,0,N-1){
    FOR(j,0,M-1){
      cin>>A[i][j];
    }
  }
  FOR(i,0,N-1){
    ll tmp=0;
    FOR(j,0,M-1){
      tmp=tmp+A[i][j]*B[j];
      //cout<< A[i][j]<<" "<<B[j]<<" q"<<tmp<<endl;
      //cout<< A[i][j]*B[j]<<" "<<tmp<<endl;
    }
    if(tmp+C>0){
      ans++;
    }
      //cout<<tmp<<" "<<C<<endl;
  }

  cout<<ans<<endl;
 

 
}
 


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")
from collections import Counter
import heapq


class MinHeap(object):
    def __init__(self, x):
        self.heap = [e for e in x]
        heapq.heapify(self.heap)

    def push(self, value):
        heapq.heappush(self.heap, value)

    def pop(self):
        return heapq.heappop(self.heap)


def solve(N: int, K: int, a: "List[int]", b: "List[int]"):
    mh = MinHeap([])
    counter = Counter()
    for aa, bb in zip(a, b):
        if aa not in counter:
            mh.push(aa)
        counter[aa] += bb
    # print(mh.heap)
    # print(counter)

    while True:
        m = mh.pop()
        if counter[m] >= K:
            break
        else:
            K -= counter[m]
    print(m)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]"
    b = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, K, a, b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 17580
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

class cake{
    public:
    int w,d,t;
    cake(){};
    cake(int _w,int _d,int _t) :w(_w),d(_d),t(_t){
    }
    bool operator<(const cake& c){
        if(t == c.t){
            return w * d < c.w*c.d;
        }
        return t < c.t;
    }
    pair<cake,cake> cut(int k,int t){
        while(1){
            if(k > w){
                k -= w;
            }
            else{
                if(k  < (w-k)){
                  return (make_pair(cake(k,d,t),cake(w-k,d,t+1)));
                }
                else{
                    return (make_pair(cake(w-k,d,t),cake(k,d,t+1)));
                }
            }
            if(k > d){
                k -= d;
            }
            else{
                if(k < (d-k))
                    return (make_pair(cake(w,k,t),cake(w,d-k,t+1)));
                else
                    return (make_pair(cake(w,d-k,t),cake(w,k,t+1)));
            }
        }
    }
};
bool comp(const cake &a,const cake &b)
{
    return a.w*a.d < b.w*b.d;

}
int main(){
    int n,w,d;
    while(cin >> n >> w >> d && n + w + d){
        vector<cake> v;
        v.push_back(cake(w,d,0));
        for(int i = 0; i < n;++i){
            int j,k;
            cin >> j >> k;
            auto t = v[j-1].cut(k,i*2);
            v.erase((v.begin()+j-1));
            v.push_back(t.first);
            v.push_back(t.second);
            sort(v.begin(),v.end());
        }
        sort(v.begin(),v.end(),comp);
        for(int i = 0; i < v.size(); ++i){
            if(i) cout << ' ';
            cout << v[i].w*v[i].d;
          // cout << v[i].t << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3084
/*author  ADITYA BANSAL
                 //~ MNNIT ALLAHABAD     */
        #include<bits/stdc++.h>
        using namespace std;
         #define ll long long
        //~ #define ll int
        ll power(ll,ll);
        ll ncr(ll,ll);
        ll add(ll a,ll b);
        void fact();
        ll mul(ll a,ll b);
        #define watch(x) cerr<<(#x)<<"is"<<x<<nl;
        #define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
        #define fi(a,b) for(ll i=a; i<b; i++)
        #define fk(a,b) for(ll k=a; k<b; k++)
        #define fri(a,b) for(ll i=a; i>b; i--)
        #define fj(a,b) for(ll j=a; j<b; j++)
        #define ffi(a,b) for(ll i=a;i*i<=b;i++)
        #define mp make_pair
        #define ff first 
        #define  tc ll t; cin>>t; while(t--)
        #define all(v) (v).begin(),(v).end()
        #define ss second
        #define pb push_back
        #define mem(v,a) memset((v),a,sizeof(v));
        #define pll pair<ll,ll>
        #define mll map<ll,ll>
        #define sll set<ll>
        #define vll vector<ll>
        #define max3(a,b,c) max(a,max(b,c))
        #define min3(a,b,c) min(a,min(b,c))
        #define nl endl
         int mod=1e9+7;
        const ll  N=100002LL;
        ll fac[N+2];
        ll inv[N+2];
     
      
        signed main(){  
    		fast
    	 //~ tc
    	
        {
		 
		ll n;
		cin>>n;
		string s;
		cin>>s;
	 ll ans=0;
		fi(0,n){ 
			
			if(s[i]!=s[i+1]) ans++;
			
		}
		cout<<ans;
	    }
            return 0;
        }
         
         
        /******************************************************************************/
         
        ll add(ll a,ll b){
			a+=b+mod;
		   if(a>=mod) a-=mod;
		   
		   return a;
		} 
         
        ll mul(ll a,ll b){
            return ((a)*1ULL*(b))%mod;
        }
         
        ll power(ll a,ll n){
          ll res=1;
          while(n){
              if(n&1) res= mul(res,a);
             n>>=1; 
             a= mul(a,a);
          }
            return res;
        }
        void fact(){
        	inv[0]=fac[0]=1;
        	fi(1,N){
        	 fac[i]=mul(fac[i-1],i);
        	inv[i]=power(fac[i],mod-2);
        }
        }
         
        ll ncr(ll n,ll r){
        	
        	if(r>n) return 0;
        	ll e=fac[n];
        	e=mul(e,inv[r]);
        	e=mul(e,inv[n-r]);
        	return e;
        }


Measured memory_bytes: 512
#include <stdio.h>

int student[100005][2];

int main() {

	int N;

	scanf("%d",&N);

	int i;

	for (i = 0; i < N; i++) {
		int A;
		scanf(" %d",&A);
		student[A][0]++;
		student[A][1] = i + 1;
	}

	for (i = 1; i <= 100000; i++) {
		if (student[i][0] > 0) { 
			if (i == N) { 
				printf("%d\n",student[N][1]);
				break;
			}
			printf("%d ",student[i][1]);
		}
	}

	return 0;
}

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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define drrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int MOD = 1'000'000'000 + 7;
const int INF = 1'000'000'000 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);

  int h, w, k;
  std::cin >> h >> w >> k;
  char cake[h][w];
  vector<vi> ans(h, vi(w, -1));
  int num = 1;
  rep(i, h) rep(j, w) {
    std::cin >> cake[i][j];
    if (cake[i][j] == '#')
      ans[i][j] = num++;
  }
  rep(i, h) {
    int cur = -1;
    rep(j, w) {
      if (ans[i][j] != -1) {
        cur = ans[i][j];
        continue;
      }
      if (cur == -1) continue;
      ans[i][j] = cur;
    }
    drep(j, w) {
      if (ans[i][j] != -1) {
        cur = ans[i][j];
        continue;
      }
      if (cur == -1) continue;
      ans[i][j] = cur;
    }
  }
	rrep(i, h-1) {
		if (ans[i][0] != -1) continue;
		rep(j, w) {
			ans[i][j] = ans[i-1][j];
		}
	}
	for(int i = h-2; i >= 0; i--) {
		if (ans[i][0] != -1) continue;
		rep(j, w) {
			ans[i][j] = ans[i+1][j];
		}
	}
	rep(i, h) {
		rep(j, w) std::cout << ans[i][j] << " ";
		std::cout << "\n";
	}
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
 
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)
 
constexpr int MOD = 1e+9 + 7;
template <typename T>
T gcd(T a, T b)
{
    if(b == 0) return a;
    else return gcd<T>(b, a % b);
}
 
template <typename T>
T pow_mod(T n, T p, T m)
{
    if(p == 0) return 1;
    if(p%2 == 1) return pow_mod<T>(n, p-1, m) * n % m;
    else{
        T tmp = pow_mod<T>(n, p/2, m) % m;
        return tmp * tmp % m;
    }
}
 
int main()
{
    int N;
    cin >> N;
    map<pair<long long,long long>, pair<int,int>> P;
    int num_zeros = 0;
    for(int i=1;i<=N;i++){
        long long A, B;
        cin >> A >> B;
        if(A == 0 and B == 0){
            ++num_zeros;  
            continue;
        }
        long long GCD = gcd<long long>(A, B); 
        A /= GCD;
        B /= GCD;
        if(B < 0){ 
            A = -A;  
            B = -B;
        }
        if(A > 0) P[make_pair(A, B)].first++;
        else P[make_pair(B, -A)].second++;
    }
 
    long long ans = 1;
    for(auto p: P){
        int num_i = p.second.first;
        int num_j = p.second.second;
        long long num_pairs = pow_mod<long long>(2, num_i, MOD) + pow_mod<long long>(2, num_j, MOD) - 1;
        ans *= num_pairs%MOD;
        ans %= MOD;
    }
    cout << (ans+num_zeros-1+MOD)%MOD << endl;
 
    return 0;
}

Measured memory_bytes: 16056
import java.util.*;
import static java.lang.System.*;

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    Scanner sc = new Scanner(in);
    int N = Integer.parseInt(sc.next());
    int x[] = new int[N];
    int y[] = new int[N];
    int h[] = new int[N];
    for(int i=0; i<N; i++){
      x[i] = Integer.parseInt(sc.next());
      y[i] = Integer.parseInt(sc.next());
      h[i] = Integer.parseInt(sc.next());
    }
    boolean check = true;
    for(int i=0; i<=100; i++){
      for(int w=0; w<=100; w++){
        check = true;
        int tmp = 0;
        for(int k=0; k<N; k++){
          if(h[k] != 0) tmp = h[k] + Math.abs(x[k] - i) + Math.abs(y[k] - w);
        }
        for(int j=0; j<N; j++){
          if(h[j] != Math.max(tmp - Math.abs(x[j] - i) - Math.abs(y[j] - w), 0) ){
            check = false;
            break;
          }
        }
        if(check == true){
          out.println(i + " " + w + " " + tmp);
          break;
        }
      }
      if(check == true) break;
    }   
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}

Measured memory_bytes: 23764
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
 
vector<int> count_sum;
 
int main(){
	int n, q;
	cin >> n >> q;
 
	char b;
	int flag = 0;
 	int count = 0;

	for(int i = 0; i < n; ++i){
		cin >> b;
 
		if(b == 'A'){
			flag = 1;
		}else if((flag == 1) && (b == 'C')){
			flag = 2;
		}else{
			flag = 0;
		}
 
		if(flag == 2){
			++count;
		}

		count_sum.push_back(count);
	}
 
 	int l, r;
	for(int i = 0; i < q; ++i){
		cin >> l >> r;
 
		cout << (count_sum[r-1] - count_sum[l-1]) << endl;
	}
 
	return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
	typedef long long int lli;
	const int MaxN=200005;
	#define fst first
	#define snd second
	int sz[MaxN];
int main(){
	lli v,N,i,p,t=0;
	cin>>N;
	for(i=2;i<=N;i++){
		cin>>p;
		sz[p]+=1;
	}
	for(i=1;i<=N;i++){
		cout<<sz[i]<<"\n";
	}
}

Measured memory_bytes: 3880
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>
#include <stack>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator<< (ostream &out, const vector<int> &b) {
    for (auto k : b) out << k << " ";
    return out;
}

istream& operator>> (istream& in, pii& b) {
    in >> b.first >> b.second;
    return in;
}

ostream& operator<< (ostream& out, const pii& b) {
    out << "{" << b.first << ", " << b.second << "}";
    return out;
}

template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;}


#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 10;
#else
    #define dbg(x) 57
    const int INF = 1e18;
    // const int mod = 2600000069;  
    // const int p = 179;
#endif

const ld PI = acos(-1);

#define time clock() / (double) CLOCKS_PER_SEC

// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,sse3,sse4")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("avx2")  
// #pragma GCC optimize("section-anchors")
// #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
// #pragma GCC optimize("vpt")
// #pragma GCC optimize("rename-registers")
// #pragma GCC optimize("move-loop-invariants")
// #pragma GCC optimize("unswitch-loops")
// #pragma GCC optimize("function-sections")
// #pragma GCC optimize("data-sections")

mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

const int MAXN = 51;
const int A = 2510;

int n, x;
int a[MAXN];
int dp[MAXN][MAXN][A];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> x;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    dp[0][0][0] = 1;
    dp[0][1][a[0]] = 1;
    for (int i = 1; i < n; i++) {
        dp[i][0][0] = 1;
        for (int j = 1; j <= i + 1; j++) {
            for (int s = 0; s < A; s++) {
                dp[i][j][s] = dp[i - 1][j][s];
                if (s >= a[i]) {
                    dp[i][j][s] += dp[i - 1][j - 1][s - a[i]];
                }
            }
        }
    }
    int ans = 0;
    for (int i = x; i < A && i / x < MAXN; i += x) {
        ans += dp[n - 1][i / x][i];
    }
    cout << ans << "\n";
}
/*

*/

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

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

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

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

  int max = b / a;
  int ans;

  if (c <= max) {
    ans = c;
  } else {
    ans = max;
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
	int n, a, b;
	scanf("%d %d %d", &n, &a, &b);
	
	auto cnton = [&](int x) {
		return __builtin_popcount(x);
	};
	
	auto ok = [&](int a,int b) {
		return (cnton(a) + cnton(b)) & 1;
	};
	
	if (!ok(a, b)) {
		puts("NO");
		return false;
	}
	
	auto bit = [&](int x,int id) {
		return (x >> id) & 1;
	};
	
	function<vector<int>(int,int,vector<int>)> solve = [&](int from,int to,vector<int> val) {
		if (val.size() == 2) {
			vector<int> ans;
			ans.push_back(from);
			ans.push_back(to);
			return ans;
		} else {
			int id = -1;
			for (int i = 0; i < n; ++i) {
				if (bit(from, i) != bit(to, i)) {
					id = i;
					break;
				}
			}
			vector<int> valL, valR;
			for (int v : val) {
				if (bit(v, id) == bit(from, id)) {
					valL.push_back(v);
				} else {
					valR.push_back(v);
				}
			}
			for (int v : valL) {
				if (ok(from, v)) {
					vector<int> ll = solve(from, v, valL);
					vector<int> rr = solve(v ^ (1 << id), to, valR);
					vector<int> ans;
					for (int u : ll) ans.push_back(u);
					for (int u : rr) ans.push_back(u);
					return ans;
				}
			}
		}
	};
	
	vector<int> val;
	for (int i = 0; i < (1 << n); ++i) val.push_back(i);
	auto ans = solve(a, b, val);
	puts("YES");
	for (int v : ans) printf("%d ", v);
}

Measured memory_bytes: 4088
#!/usr/bin/env python3
import sys
import math
sys.setrecursionlimit(500005)


def solve(N: int):
    rn = math.ceil(math.sqrt(N))
    arr = [0] * N
    counter = 0
    for x in range(1,rn+1):
        for y in range(1,rn+1):
            for z in range(1,rn+1): 
                if ((x*x+y*y+z*z+x*y+y*z+z*x) > N ):
                    continue
                else:
                    arr[(x*x+y*y+z*z+x*y+y*z+z*x) -1 ] += 1
    for i in arr:
        print(i)

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()

A = []
i = 1
while 5 ** i * 2 <= INF:
    A.append(5**i * 2)
    i += 1

if N % 2 == 0:
    ans = 0
    for a in A:
        ans += N // a
    print(ans)
else:
    print(0)


Measured memory_bytes: 3064
n = int(input())
a = list(map(int,input().split()))
now = [0,0,0]
mod = 10 ** 9 + 7
ans = 1
for x in a:
  tmp = 0
  for k in range(3):
    if now[k] == x:
      if tmp == 0:
        now[k] += 1
      tmp += 1
  ans *= tmp
  ans %= mod
print(ans)
#print(now)

Measured memory_bytes: 14396
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while (cin >> n && n) {
    vector<PI> a(n);
    REP(i, 0, n) {
      int x, y;
      cin >> x >> y;
      a[i] = PI(y, x);
    }
    sort(a.begin(), a.end());
    int tot = 0;
    bool ok = 1;
    REP(i, 0, n) {
      tot += a[i].second;
      if (tot > a[i].first) {
        ok = 0;
        break;
      }
    }
    cout << (ok ? "Yes" : "No") << endl;
  }
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main()
{
	int h, w, n;
	cin >> h >> w >> n;
	vector<P> ab(n);
	for (int i = 0, a, b; i < n; i++) {
		cin >> a >> b;
		ab[i] = { a, b };
	}
	sort(ab.begin(), ab.end());
	vector<int> val(w);
	for (int i = 0; i < w; i++) {
		val[i] = i;
	}
	for (int i = 0; i < n; i++) {
		int c = ab[i].first - 1; c = (-c % (w * 2) + w * 2) % (w * 2);
		int l = ab[i].second - 1;
		int r = ab[i].second;
		int v = ((l & 1) != (c & 1) ? w * 2 - 1 - l + c : l + c) % (w * 2);
		l = v >= w ? w * 2 - 1 - v : v;
		v = ((r & 1) != (c & 1) ? w * 2 - 1 - r + c : r + c) % (w * 2);
		r = v >= w ? w * 2 - 1 - v : v;
		swap(val[l], val[r]);
	}
	vector<int> res(w);
	for (int i = 0; i < w; i++) {
		int v = (i & 1 ? w + (w - 1) - i + h : i + h) % (w * 2);
		res[val[i]] = v >= w ? w * 2 - 1 - v + 1 : v + 1;
	}
	for (int i = 0; i < w; i++) {
		cout << res[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 5880
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func min(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m := nextInt(), nextInt()
	var ans int
	if n <= m/2 {
		ans = n + (m-2*n)/4
	} else {
		ans = m / 2
	}
	puts(ans)
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define debug(a) cout<<a<<endl
#define pii pair<int,int>
#define maxn 100009
#define inf (int) 1e9+7
using namespace std;
bool cmp(pair<string,pair<int,int> > a,pair<string,pair<int,int> > b){
    if(a.first<b.first)return true;
    else if(a.first>b.first)return false;
    else{
        if(a.second.first>b.second.first)return true;
        else return false;
    }
}
int main(){
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<pair<string,pair<int,int> > > nomes;
    vector<pair<string,int> >ans;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        int a;
        cin>>a;
        ans.push_back({s,a});
        nomes.push_back({s,{a,i+1}});
    }
    sort(nomes.begin(),nomes.end(),cmp);
    for(auto e:nomes){
        cout<<e.second.second<<endl;
    }
    return 0;
}
///usar double sempre ou long double
///pensar em casos que coisas dao negativas
///N esquecer de limpar as coisas em quest de varios testes
///OLHAR A COMPLEXIDADE PRA VER SE N PASSA POR BRUTE FORCE OU BRUTE FORCE COM ALGUMAS OTIMIZACOES

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long int ll;

int main(){
    ll a,b; cin >> a >> b;
    if(a==b){
        cout << 1 << endl;
        return 0;
    }
    ll ans=0;
    int t,u;
    for(int i=61;i>=0;i--){
        if(a>=(1LL<<i)){
            a-=(1LL<<i); b-=(1LL<<i); //上位桁が1の場合は余分なので除く
        }
        if(b>=(1LL<<i)){
            t=i;break;
        }
    }
    b-=(1LL<<t);
    for(u=0;;u++){
        if((1LL<<u)>b)break;
    }
    ll mi=a,ma=(1LL<<u);
    ans+=(1LL<<t)-mi;
    if(ma>=mi){
        ans+=(1LL<<t);
    }
    else{
        ans+=ma+(1LL<<t)-mi;
    }
    cout << ans << endl;
}

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

int main() {
  long long n, k;
  cin >> n >> k;
  long long ans = 0;
  ans += 5*((n - 2)/11);
  for (long long i = 1; i <= (n - 2)%11; i++) {
    for (long long j = 1; j <= 5; j++) {
      long long sum = 9*(7*i + j + 1);
      if (sum%11 == k) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#define int long long 
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int a[214514], b[214514]; int n, cnta = 0;
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	rep(i, n)b[i] = a[i] - (i + 1);
	sort(b, b + n);
	rep(i, n) {
		if (n % 2 == 1)cnta += abs(b[i] - b[(n - 1) / 2]);
		else cnta += abs(b[i] - (b[n / 2] + b[n / 2 - 1]) / 2);
	}
	cout << cnta << endl;
	getchar(); getchar(); return 0;
}

Measured memory_bytes: 3328
'use strict'

function main(s) {

  s = s.split('\n');
  const n = Number(s[0].split(' ')[0]);
  const x = Number(s[0].split(' ')[1]);
  const donuts = s.slice(1, -1).map(el => Number(el));

  donuts.sort((a, b) => a - b);
  const sum = donuts.reduce((a, b) => a + b);
  const ans = Math.floor((x - sum) / donuts[0]) + donuts.length;

  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
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 N; cin >> N;
  vector<ll> A(N); rep(i,N) cin >> A[i];
  ll allxor=0;
  rep(i,N) allxor ^= A[i];
  rep(i,N){
    if(i) cout << " ";
    cout << (allxor^A[i]);
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 4792
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s-1);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

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

    int size = s.size()-1;
    ll sum = 0;

    REP(i, 1 << size) {
        ll num = 0;
        REP(j, size) {
            num += s[j] - '0';
            if(i & (1 << j)) {
                sum += num;
                num = 0;
            } else {
                num *= 10;
            }
        }
        num += s[size] - '0';
        sum += num;
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
s=input()
t=input()

def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

def lcm(a,b):
    return a*b//gcd(a,b)

L=lcm(n,m)

isGood=True
cycle_s=L//n
cycle_t=L//m
cycle_lcm=lcm(cycle_s,cycle_t)
for i in range((L//cycle_lcm)):
    if s[cycle_lcm*i//cycle_s]!=t[cycle_lcm*i//cycle_t]:
        isGood=False
        break

if(isGood):
    print(L)
else:
    print(-1)

Measured memory_bytes: 9300
#include <iostream>
using namespace std;
template
<
    typename TYPE,
    std::size_t SIZE
>
std::size_t array_length(const TYPE (&)[SIZE])
{
    return SIZE;
}

int main() {
    int N;
    cin >> N;
    int A[N], B[N];
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for(int i = 0; i < N; i++) {
        B[A[i] - 1] = i + 1; 
    }
    for(int i = 0; i < N; i++) {
        cout << B[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1536
%:pragma GCC optimize("Ofast", "inline")
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}

namespace {
    const int mo = 1e9 + 7;
    inline int add(int x, int y) { x += y; return x >= mo ? x - mo : x; }
    inline int sub(int x, int y) { x -= y; return x < 0 ? x + mo : x; }
    inline int mul(int x, int y) { return (lo) x * y % mo; }
    inline int power(int a, int k = mo - 2) {
		int ans = 1;
		for (; k; k >>= 1, a = mul(a, a))
			if (k & 1) ans = mul(ans, a);
		return ans;
    }
	inline void U(int &x, int y) { x = add(x, y); } 
}

const int N = 333;
int n, K;
int dp[N][N][N];
char str[N];

inline int dfs(int l, int r, int k) {
	if (k < 0) return -1e9;
	if (l > r) return 0;
	if (l == r) return 1;
	if (~dp[l][r][k]) return dp[l][r][k];
	int &ans = dp[l][r][k] = 0;
	ans = max(ans, max(dfs(l + 1, r, k), dfs(l, r - 1, k)));
	ans = max(ans, 2 + dfs(l + 1, r - 1, k - 1));
	ans = max(ans, (str[l] == str[r]) * 2 + dfs(l + 1, r - 1, k));
	// cout << l << " " << r << " " << k << " "<< ans << "\n";
	return ans;
}

int main(void) {
	memset(dp, -1, sizeof dp);
	scanf("%s", str + 1);
	n = strlen(str + 1);
	read(K);
	// cout << dfs(1, n, K) << "\n";
	// return 0;
	int ans = 0;
	rep (r, n) rep (l, r) ans = max(ans, dfs(l, r, K));
	cout << ans << "\n";
}


Measured memory_bytes: 144640
#include <bits/stdc++.h>
using namespace std;
int main() {
    int D, G, p[11], c[11];
    cin >> D >> G;
    for (int i = 0; i < D; ++i) {
        cin >> p[i] >> c[i];
    }

    int ans = 1e9;
    for (int mask = 0; mask < (1 << D); mask++) {
        int sum = 0, count = 0, max = 0;

        for (int i = 0; i < D; i++) {
            if (mask & (1 << i)) {
                sum += p[i] * 100 * (i + 1) + c[i];
                count += p[i];
            }
            else {
                max = i;
            }
        }

        int point = G - sum;
        if (point < 0) {
            ans = min(ans, count);
            continue;
        }

        int tmpCount = (point + (max + 1) * 100 - 1) / ((max + 1) * 100);
        if (tmpCount <= p[max]) {
            ans = min(ans, count + tmpCount);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<iostream>
#define LL long long
using namespace std;
int a[310][310],n;
LL ans=0;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++) scanf("%d",&a[i][j]);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
		{
			bool flag=false;
			for(int k=1;k<=n;k++) if(i!=k&&j!=k)
			{
				if(a[i][j]>a[i][k]+a[k][j]) return puts("-1"),0;
				if(a[i][j]==a[i][k]+a[k][j]) flag=true;
			}
			if(!flag) ans+=a[i][j];
		}
	printf("%lld",ans);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iostream>
//#include <vector>
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
 
int main(){
    int n,v,j;
    cin>>n;
    
    vector<int> a(n);
    rep(i,n)cin>>a.at(i);
    
    rep(i,n){
      v=a.at(i);
      j=i-1;
      
      while(j>=0&&a.at(j)>v){
          a.at(j+1)=a.at(j);
          j--;
          a.at(j+1)=v;
      }
      rep(i,n-1)cout<<a.at(i)<<" ";
      cout<<a.at(n-1)<<endl;
    }
    
    
    
    
    
}
  




Measured memory_bytes: 3116
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int N,Q;
char s[100010];
int f[100010];
int main()
{
    cin>>N>>Q;
    //cin>>s+1;
    scanf("%s",s+1);
    for(int i=2;i<=N;i++){
        if(s[i]=='C'&&s[i-1]=='A'){
            f[i]=1;
        }
        f[i]=f[i]+f[i-1];
    }
    int l,r;
    while(Q--){
        cin>>l>>r;
        cout<<f[r]-f[l]<<endl;
    }
    return 0;
}


Measured memory_bytes: 1280
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

const ll mod = 998244353;

ll mod_pow(ll a, ll b) { return b ? (b & 1 ? a : 1) * mod_pow(a * a % mod, b / 2) % mod : 1; }

ll solve() {
    ll N;
    cin >> N;
    V<ll> cnt(N);
    for(ll i = 0; i < N; i++) {
        ll e;
        cin >> e;
        if(i == 0 && e != 0) return 0;
        if(i != 0 && e == 0) return 0;
        cnt[e]++;
    }
    
    if(cnt[0] != 1) return 0;
    ll ans = 1;
    for(ll i = 1; i < N; i++) {
        if(cnt[i] == 0) {
            bool ok = true;
            for(ll j = i; j < N; j++) if(cnt[j]) ok = false;
            if(!ok) return 0;
            break;
        }
        ll pre = cnt[i - 1];
        (ans *= mod_pow(pre, cnt[i])) %= mod;
    }

    return ans;
}

int main() {
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 1024
#BFS
from collections import deque
def bfs(i, j):
    q=deque()
    q.append((i, j))
    log = [[-1] * w for i in range(h)]
    log[i][j] = 0

    distance = 0
    d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    while q:
        #qの先頭を取り出す
        p=q.popleft()
        for x, y in d:
            nx = p[0] + x
            ny = p[1] + y
            if not(0 <= nx <h and 0 <= ny < w):continue
            if s[nx][ny] == "#":continue
            if log[nx][ny] >= 0:continue
            log[nx][ny] = log[p[0]][p[1]] + 1
            q.append((nx, ny))
            if distance < log[nx][ny]:distance = log[nx][ny]

    return distance

h, w = map(int,input().split())
s = [list(input()) for i in range(h)]
distance = 0

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":continue
        temp = bfs(i, j)
        if temp >= distance:distance = temp
print(distance)


Measured memory_bytes: 3316
n = int(input())
dic = {}
for i in range(n):
    w = input()
    if dic.get(w) is None:
        dic[w] = 1
    else:
        dic[w] += 1

ans = sorted(dic.items(), key=lambda x:x[1],reverse=True)

maxn = ans[0][1]

ans = [x for x,y in ans if maxn==y]
ans.sort()
for i in ans:
    print(i)

Measured memory_bytes: 43224
#include <iostream>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define EUC_DIS(x, y) sqrt(x*x + y*y)

const int MOD = (int)1000000007;

typedef long long ll;
using namespace std;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    ll power = 1;

    FOR(i, 1, N+1){
        power = (i % MOD) * (power % MOD) % MOD;
    }

    cout << power << '\n';

    return 0;
}


Measured memory_bytes: 256
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    vector<string> a(2);
    rep(i, 2) cin >> a[i];
    if (a[0][0] == a[1][2] && a[0][1] == a[1][1] && a[0][2] == a[1][0]) puts("YES");
    else puts("NO");
}


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

#include <vector>
#include <cmath>
#include <limits>
#include <functional>
using namespace std;

int main()
{
    int N, K;

    int ans = 0, max = 0;

    cin >> N >> K;

    vector<int> a(N);
    vector<int> b(N);
    for (int i = 0; i < N; i++)
        b[i] = 0;

    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
        b[a[i] - 1]++;
    }

    sort(b.begin(), b.end(), greater<int>()); // 降順（大きい順）でソー

    for (int i = K; i < N; i++)
    {
        ans += b[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4468
#include <stdio.h>
int main(){
	int a ,b ,d ,r ,f;
	scanf ("%d %d",&a ,&b);
	d = a / b;
	r = a % b;
	double f1;
	f1 = 1.0000 * a/b;
	printf("%d %d %.5lf\n" ,d ,r ,f1);
	
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
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; }
const ll INF = 1LL << 60;
int main(){
    double w,h,x,y;
    cin >> w >> h >> x >> y;
    double ans = w * h / 2.0;
    int ok = 0;
    if(x==w/2 && y==h/2) ok = 1;

    printf("%.10f %d\n",ans,ok);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    ll a,b,c;
    cin>>a>>b>>c;
    if(a%2||b%2||c%2){
        cout<<0<<endl;
        return 0;
    }
    if(a==b&&b==c){
        cout<<-1<<endl;
        return 0;
    }

    ll ans = 0;
    map<tuple<ll,ll,ll>,ll> m;
    while(true){
        ll a1=0,b1=0,c1=0;
        a1+=b/2+c/2;
        b1+=a/2+c/2;
        c1+=a/2+c/2;
        tuple<ll,ll,ll> m2 = make_tuple(a1,b1,c1);
        ans++;
        if(m[m2]!=0){
            cout<<-1<<endl;
            return 0;
        }else{
            if(a1%2||b1%2||c1%2){
                cout<<ans<<endl;
                return 0;
            }
            m[m2]++;
        }
        a=a1;
        b=b1;
        c=c1;

    }




    return 0;
}


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

map<string, int> mapstring;
pair<string, int> cnt[200005];

bool compar(pair<string, int> a, pair<string, int> b){
	if(a.second > b.second)
		return true;
	if(a.second < b.second)
		return false;
	return a.first < b.first;
}

int main(){
	int n;
	string s;
	int idx = 1;
	cin >> n;
	for(int i = 0 ; i < n ; i++){
		cnt[i].second = 0;
	}
	for(int i = 0 ; i < n ; i++){
		cin >> s;
		if(mapstring[s] == 0){
			cnt[idx].first = s;
			cnt[idx].second++;
			mapstring[s] = idx;
			idx++;
		}
		else{
			cnt[mapstring[s]].second++;
		}
	}
	sort(cnt+1, cnt+idx, compar);
	cout << cnt[1].first << endl;
	for(int i = 2 ; i < idx ; i++){
		if(cnt[i].second == cnt[1].second ){
			cout << cnt[i].first << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 28288