akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define R register
#define mp make_pair
#define ll long long
#define pii pair<int, int>
using namespace std;
const int inf = 1e9;

int n, a[20], b[20], pos[20];
vector<int> tmp, buc[55][2];

template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}

int main() {
    read(n);
    for (R int i = 0; i < n; ++i) read(a[i]);
    for (R int i = 0; i < n; ++i) read(b[i]);
    int ans = inf;
    for (R int i = 0; i < 1 << n; ++i) {
        int num = 0;
        for (R int j = 0; j < n; ++j) num ^= (i >> j) & 1;
        if (num) continue;
        tmp.clear();
        for (R int i = 0; i <= 50; ++i) buc[i][0].clear(), buc[i][1].clear();
        for (R int j = 0; j < n; ++j) {
            int w = i & (1 << j) ? b[j] : a[j];
            tmp.push_back(w);
            buc[w][((i >> j) ^ j) & 1].push_back(j);
        }
        sort(tmp.begin(), tmp.end());
        int fl = 1;
        for (R int j = n - 1; fl && ~j; --j) {
            if (!buc[tmp[j]][j & 1].size()) fl = 0;
            else {
                pos[buc[tmp[j]][j & 1].back()] = j;
                buc[tmp[j]][j & 1].pop_back();
            }
        }
        if (!fl) continue;
        int sum = 0;
        for (R int j = 0; j < n; ++j)
            for (R int k = 0; k < j; ++k)
                sum += pos[k] > pos[j];
        ans = min(ans, sum);
    }
    printf("%d\n", ans == inf ? -1 : ans);
    return 0;
}

Measured memory_bytes: 384
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXH=1000;
const int MAXW=1000;
const int MOD=1000000007;
void inc(int &a,int b) { if((a+=b)>=MOD) a-=MOD; }

int h,w;
char g[MAXH][MAXW+1];

int dp[MAXH][MAXW];

int solve() {
	memset(dp,0,sizeof(dp));
	for(int x=h-1;x>=0;--x) for(int y=w-1;y>=0;--y) {
		if(x==h-1&&y==w-1) { inc(dp[x][y],1); continue; }
		if(g[x][y]=='#') continue;
		if(x+1<h) inc(dp[x][y],dp[x+1][y]);
		if(y+1<w) inc(dp[x][y],dp[x][y+1]);
	}
	return dp[0][0];
}

void run() {
	scanf("%d%d",&h,&w);
	REP(x,h) scanf("%s",g[x]);
	printf("%d\n",solve());
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 5120
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,a[3][500],s[500];
	cin>>n;
	for(int i=0;i<n;i++){
		s[i]=0;
		for(int j=0;j<3;j++)
			cin>>a[j][i];
	}
	for(int i=0;i<3;i++){
		for(int j=0;j<n;j++){
			bool t=true;
			for(int k=0;k<n;k++){
				if(j!=k&&a[i][j]==a[i][k])
					t=false;
			}
			if(t==true)
				s[j]+=a[i][j];
		}
	}
	for(int i=0;i<n;i++)
		cout<<s[i]<<endl;
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, ll> pcl;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <functional>
#include <iostream>
using namespace std;

int main(void){
	int a[5];
	int i;

	for(i=0; i<5; i++){
		scanf("%d", &a[i]);
	}
	sort(a, a+5, greater<int>());
	for(i=0; i<4; i++){
		printf("%d ", a[i]);
	}
	printf("%d\n", a[4]);

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define mkpr(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()

typedef long long int ll;

ll general,total;
//ll num[ten5];
//ll num2[ten5];
//char cmap[10][10];
//priority_queue<ll> pqll;   //decrease
//priority_queue<double> pqd;
//stack<int> stk;
//vector<pair<ll,ll>> vpll;
//vector<pair<double,double>> vpdd;
//vector<ll> vll[ten52];
//vector<double> vd;
//deque<ll> deq[55];
//list<int> li;
//set<int> sint;
//set<ll> sll;
set<char> sch;
//map<ll,ll> mp;

ll numR[4000],numG[4000],numB[4000];

/*ll cmp(pair<ll,ll> a,pair<ll,ll> b)
{
    return a.first<b.first;
    //arrising
}*/


int main()
{
    long long int sum,sum2;
    long long int m,n,o,i,j,k=1;
    long long int a,a1,a2,a3,a4,a5,a6;
    sum=sum2=0;
    a=a1=a2=a3=a4=a5=a6=0;
    cin>>n>>a1>>m>>a2;
    while(1)
    {
        m-=a1;
        if(m<=0)
        {
            cout<<"Yes";
            break;
        }
        n-=a2;
        if(n<=0)
        {
            cout<<"No";
            break;
        }
    }
    return 0;
}





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

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

using namespace std;

int main(void)
{
	int k, t;
	cin >> k >> t;
	vec<int> a(t);
	rep(i, t) cin >> a[i];
	int sum = 0;
	rep(i, t) sum += a[i];
	int ans = 0;
	rep(i, t) {
		if (sum < a[i] * 2 + 1) ans += a[i] - (sum - a[i] + 1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
  
int main(){
    int cost[22][22]={0};
    int n,m,i,j,k,a,b,c,d;
    char cc;
    cin>>n>>m;
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            cost[i][j] = 1<<28;
        }
    }
    for(i=0;i<m;i++){
        cin>>a>>cc>>b>>cc>>c>>cc>>d;
        cost[a][b]=c;cost[b][a]=d;
    }
    for(k=1;k<=n;k++)
      for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
    cin>>a>>cc>>b>>cc>>c>>cc>>d;
    cout << c-d-cost[a][b]-cost[b][a] << endl;
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var k = Math.Ceiling((double) n / 1000);
            Console.WriteLine(1000 * k - n);
        }
    }
}

Measured memory_bytes: 27580
#include <stdio.h>

int main(void)
{
  int N,N_c;
  scanf ("%d",&N);
  N_c=N;
  char S[N];
  scanf ("%s",S);
  int K;
  scanf ("%d",&K);
  char target = S[K-1];
  while (N_c)
  {
    if (S[N_c-1]!=target) S[N_c-1]='*';
    N_c--;
  }
  printf ("%s",S);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int h, w;
    cin >> h >> w;
    string s[h];
    rep(i, h)
    {
        cin >> s[i];
    }
    set<int> height;
    set<int> width;
    rep(i, h)
    {
        bool flag = false;
        if (s[i][0] == '.')
        {
            rep(j, w)
            {
                if (s[i][j] == '#')
                    goto LOOPOUT;
            }
            height.insert(i);
        }
    LOOPOUT:;
    }
    rep(j, w)
    {
        bool flag = false;
        if (s[0][j] == '.')
        {
            rep(i, h)
            {
                if (s[i][j] == '#')
                    goto LOOPAUTO;
            }
            width.insert(j);
        }
    LOOPAUTO:;
    }
    rep(i, h)
    {
        if (height.find(i) != height.end())
            continue;
        rep(j, w)
        {
            if (width.find(j) != width.end())
                continue;
            else
            {
                cout << s[i][j];
            }    
        }
            cout << endl;
    }
    return 0;
}

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

class Main{
  public static void main(String[]arge){
    Scanner scanner = new Scanner(System.in);
    int count_500yen = scanner.nextInt();
    int count_100yen = scanner.nextInt();
    int count_50yen = scanner.nextInt();
    int ammount_price = scanner.nextInt();

    int count = 0;

    for(int i_500 = 0; i_500<=count_500yen;i_500++){
      for(int i_100 = 0; i_100<=count_100yen;i_100++){
        for(int i_50 = 0; i_50<=count_50yen;i_50++){
          int combi = 500*i_500 + 100*i_100 + 50*i_50;
          if(ammount_price == combi) count++;
        }
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 19796
#include<stdio.h>
#define LEN 100001

typedef struct p{
  char name[10];
  int t;
} Process;

Process que[LEN];
int head=1,tail=1;

void enqueue(Process P){
  if(head-tail != 1){
    que[tail] = P;
    tail = (tail+1)%LEN;
  }
}

Process dequeue(){
  if(head != tail){
    head= (head+1)%LEN;
    if(head == 0)return que[LEN-1];
    else return que[head-1];
  }
}

void Processing(int quantam){
  Process P;
  static int totaltime=0;
  
  P = dequeue();
  if(quantam >= P.t){
    totaltime += P.t;
    printf("%s %d\n",P.name, totaltime);
  }else{
    P.t -= quantam;
    totaltime += quantam;
    enqueue(P);
  }
}


int main(){
  Process buf;
  int quantam,i,n;
  
  scanf("%d %d",&n,&quantam);
  for(i=1; i<=n; i++){
    scanf("%s %d",buf.name, &buf.t);
    enqueue(buf);
  }
  while(head != tail){
    Processing(quantam);
  }

  return 0;
}




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

class _Class
{
	void _Do()
	{
		//
		var _s = _stringArray();
		var N_ = int.Parse(_s[0]);
		var a_ = _intArray();

		Array.Sort(a_);
		var min = a_[0];
		Array.Reverse(a_);
		var max = a_[0];

		Console.WriteLine(max-min);




	}

	static void Main(string[] args)
	{
		new _Class()._Do();
	}


	// 1
	string[] _stringArray()
	{
		return Console.ReadLine().Split();
	}

	// 2.1 -2,147,483,648 ~ +2,147,483,647
	int[] _intArray()
	{
		var _s = Console.ReadLine().Split();

		var x = new int[_s.Length];
		for (var i = 0; i < _s.Length; i++)
			x[i] = int.Parse(_s[i]);

		return x;
	}

	// 2.2 -9,223,372,036,854,775,808 ~ +9,223,372,036,854,775,807
	long[] _longArray()
	{
		var _s = Console.ReadLine().Split();

		var x = new long[_s.Length];
		for (var i = 0; i < _s.Length; i++)
			x[i] = long.Parse(_s[i]);

		return x;
	}
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main() {
  INIT;
  VAR(int,n,m);
  if(n==1){
    if(m==1) {
      OUT(1)BR;
      return 0;
    }
    OUT(max(0LL, m-2))BR;
    return 0;
  }
  if(m==1){
    OUT(max(0LL, n-2))BR;
    return 0;
  }
  OUT(max((n-2)*(m-2), 0LL))BR;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}


int main() {
    ll n,k;
    cin >> n >> k;
    ll MOD = 1000000007;

    ll sum[150000] = {};
    int count = 0;
    ll dp[150000][k];
    rep(i,150000){
        dp[0][i] = 0;
        dp[1][i] = 0;
    }

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

    // 数数え
    srep(i,1,n){
        if(n/i<i)break;
        sum[count] = i;
        count++;
    }
    
    drep(i,count){
        if(n/sum[i] == sum[i])continue;
        sum[count] = n/sum[i];
        count++;
    }
    
    rep(i,count){
        if(i==0){
            dp[i][0] = sum[i];
        }else{
            dp[i][0] = sum[i] - sum[i-1];
        }
    }

    srep(j,1,k){
        ll tmp = 0;
        drep(i,count){
            if(i==count-1){
                tmp += dp[count-1-i][j-1];
                dp[i][j] = dp[i][0]*tmp % MOD;
            }else{
                tmp += dp[count-1-i][j-1];
                tmp %= MOD;
                dp[i][j] = dp[i][0]*tmp % MOD;
            }
        }
    }

    ll ans = 0;
    rep(i,count){
        ans += dp[i][k-1];
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}
 
 


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

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

    int n; cin >> n;
    vector<int> f(n, 0);
    for (int x = 1; x*x <= n; x++) {
        for (int y = 1; y*y <= n; y++) {
            for (int z = 1; z*z <= n; z++) {
                int c = x*x + y*y + z*z + x*y + y*z + z*x;
                if (c <= n)
                    f[c]++;
            }
        }
    }
    for (int i = 1; i <= n; i++) cout << f[i] << "\n";
    return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
long long gcd(long long a, long long b){
  if(a<b){
    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;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};
 
int main(){
  int h,w;
  cin>>h>>w;
  vector<vector<char>> table(h+2,vector<char>(w+2, '#'));
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      cin>>table[i][j];
    }
  }
  REP(i,h+2){
    REP(j,w+2){
      cout<<table[i][j];
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
from sys import setrecursionlimit

setrecursionlimit(10 ** 9)

n = int(input())

graph = []

for _ in range(n):
    tmp = list(map(int, input().split()))

    if tmp[1] == 0:
        graph.append([])
        continue
    else:
        graph.append(list(map(lambda x: x - 1, tmp[2: tmp[1] + 2])))

d = [-1] * n
f = [-1] * n

time = 1


def dfs(x):
    if d[x] != -1:
        return

    global time

    d[x] = time
    time += 1

    for n in graph[x]:
        dfs(n)

    f[x] = time
    time += 1


for i in range(n):
    dfs(i)

for i in range(n):
    print(i + 1, d[i], f[i])



Measured memory_bytes: 5664
#define M 1<<21
char*s,T[M],*r=T;H[M][27],h,U[M],V[M],n,k;main(i){for(;gets(r+1);++n)for(k=0;*++r&=31;)U[r-T]=k|=!!n<<*r;for(;--i+2;)for(k=0,s=r;--s>T;k=H[k][*s]=*s?H[k][*s]?:++h:0){n+=i*__builtin_popcount(U[s-T]&(V[k]|=!s[-1]<<*s));}printf("%d",1-n);}

Measured memory_bytes: 115736
#include <iostream>

using namespace std;

int main(void){

  int n;
  cin >> n;

  while(n--){

    int from,too;
    cin >> from >> too;

    if( from < too ){
      for( int i = from ; i <= too ; i++ ){
	if( i == too ) cout << i << endl;
	else cout << i << " ";
      }
    }
    else if( ( 0 <= from && from <= 5 ) && ( 0 <= too && too <= 5 ) ){
      for( int i = from ; i >= too ; i-- ){
	if( i == too ) cout << i << endl;
	else cout << i << " ";
      }
    }

    else if( 6 <= from && from <= 9 ){

      for( int i = from ; i <= 9 ; i++ )
	cout << i << " ";

      for( int i = 5 ; i >= too ; i-- ){
	if( i == too ) cout << i << endl;
	else cout << i << " ";
      }

      if( 6 <= too && too <= 9 ){
	cout << "5 4 3 2 1 0 1 2 3 4 5 ";   
	for( int i = 6 ; i <= too ; i++ ){
	  if( i == too ) cout << i << endl;
	  else cout << i << " ";
	}
      }

    }
    
  }
  return 0;
}

Measured memory_bytes: 1168
N, L = map(int, input().split())
 
if L > 0:
  taste = N * (L + L + N - 1) / 2 - L
elif L + N - 1 < 0:
  taste = N * (L + L + N - 1) / 2 - (L + N - 1)
else:
  taste = N * (L + L + N - 1) / 2

print(int(taste))

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    string s; ll k; cin >> s >> k;
    int n = s.size();
    int now = 1;
    ll cnt = 0;
    ll ans = 0;

    FOR(i,1,n){
        if(s[i] == s[i-1]) now++;
        else{
            cnt += now/2;
            now = 1;
        }
    }
    if(now > 1) cnt += now/2;
    
    bool ok = true;
    rep(i,n){
        if(s[i] != s[0]){
            ok = false;
            break;
        }
    }

    if(ok){
        ans = (n*k)/2;
        cout << ans << endl;
        return 0;
    }
    else if(s[0] != s[n-1]){
        ans = cnt*k;
        cout << ans << endl;
        return 0;
    }

    ll a = 0;
    ll b = 0;
    rep(i,n){
        if(s[i] == s[0]) a++;
        else break;
    }
    for(int i = n-1; i >= 0; i--){
        if(s[i] == s[n-1]) b++;
        else break;
    }

    ll dif = a/2 + b/2 - (a+b)/2;
    ans = cnt*k - dif*(k-1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define pli pair<long long , int>
#define pil pair<int ,long long>
#define pi acos(-1)
#define pb push_back
#define mkp make_pair
#define all(a) a.begin(), a.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;




int main(){
    IOS
    //freopen("output.txt","w",stdout);
    ll n;
    cin>>n;
    
    cout<<n*n*n;
}

Measured memory_bytes: 256
#include<cstdio>
const long long mod = 1e9+7;

long long power(long long a,long long b){ 
    long long res = 1;
    while(b!=0){
        if(b%2) res = res*a%mod;
        a = a*a%mod;
        b /= 2;
    }
    return res;
}

int main(){
    int n;
    scanf("%d",&n);
    long long ans = power(10,n);
    long long minus = power(9,n);
    ans = (ans-2ll*minus%mod)%mod;
    long long add = power(8,n)%mod;
    ans = (ans+add)%mod;
    if(ans<0) ans += mod;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1732
import sys

def check(pos, S, index):
    N = len(S)
    right = (index + 1) % N
    left = (index + (N - 1)) % N

    if pos[index] == 0:
        if S[index] == 'o':
            return pos[left] == pos[right]
        else:
            return pos[left] != pos[right]
    else:
        if S[index] == 'o':
            return pos[left] != pos[right]
        else:
            return pos[left] == pos[right]


def make_pos(pos, S):
    """Sheep: 0, Wolf: 1"""
    N = len(S)
    for i in range(1, N-1):
        if pos[i] == 0:
            if S[i] == 'o':
                pos[i+1] = pos[i-1]
            else:
                pos[i+1] = (pos[i-1] + 1) % 2

        else:
            if S[i] == 'o':
                pos[i+1] = (pos[i-1] + 1) % 2
            else:
                pos[i+1] = pos[i-1]

    if check(pos, S, 0) and check(pos, S, N-1):
        return pos
    else:
        return False


def main():
    input = sys.stdin.readline
    N = int(input())
    S = str(input().strip())

    # Case 1: SSxxx
    pos = [-1 for _ in range(N)]
    pos[0] = 0
    pos[1] = 0
    pos = make_pos(pos, S)
    if pos:
        ans = ['S' if n == 0 else 'W' for n in pos]
        return ''.join(ans)

    # Case 2: SWxxx
    pos = [-1 for _ in range(N)]
    pos[0] = 0
    pos[1] = 1
    pos = make_pos(pos, S)
    if pos:
        ans = ['S' if n == 0 else 'W' for n in pos]
        return ''.join(ans)

    # Case 3: WSxxx
    pos = [-1 for _ in range(N)]
    pos[0] = 1
    pos[1] = 0
    pos = make_pos(pos, S)
    if pos:
        ans = ['S' if n == 0 else 'W' for n in pos]
        return ''.join(ans)

    # Case 4: WWxxx
    pos = [-1 for _ in range(N)]
    pos[0] = 1
    pos[1] = 1
    pos = make_pos(pos, S)
    if pos:
        ans = ['S' if n == 0 else 'W' for n in pos]
        return ''.join(ans)

    return -1


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 4972
#include "bits/stdc++.h"
using namespace std;
int main(){
    int a,b,c,d,x,y,i;
    cin>>a>>b>>c>>d;
    x=c-a;
    y=d-b;
    for(i=0;i<y;i++) cout << "U";
    for(i=0;i<x;i++) cout << "R";
    for(i=0;i<y;i++) cout << "D";
    for(i=0;i<x+1;i++) cout << "L";
    for(i=0;i<y+1;i++) cout << "U";
    for(i=0;i<x+1;i++) cout << "R";
    cout << "DR";
    for(i=0;i<y+1;i++) cout << "D";
    for(i=0;i<x+1;i++) cout << "L";
    cout << "U" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  ll D;
  cin >> D;
  vector<ll> c(26);
  rep(i,26) cin >> c[i];
  vector<vector<ll>> s(D,vector<ll>(26));
  rep(i,D)
  {
    rep(j,26)
    {
      cin >> s[i][j];
    }
  }
  vector<int> t(D);
  rep(i,D)
  {
    ll M = 0;
    ll m = 0;
    rep(j,26)
    {
      M = max(M,s[i][j]);
      if(M!=m)
      {
        t[i] = j;
      }
      m = M;
    } 
  }
  vector<int> lastday(26);
  rep(i,26) lastday[i] = -1;
  ll satisfy = 0;
  rep(i,D)
  {
    ll dissatisfy = 0;
    satisfy += s[i][t[i]];
    lastday[t[i]] = i;
    rep(j,26)
    {
      dissatisfy += c[j] * (i-lastday[j]);
    }
    satisfy -= dissatisfy;
    cout << t[i] + 1 << endl;
  }
  return 0;
}


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

#define fast                     ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll                       long long 
#define mk                       make_pair
#define pb                       push_back
#define pob                      pop_back
#define pii                      pair<int,int>
#define vi                       vector<int>
#define vii                      vector<pii>
#define mi                       map<int,int>
#define mii                      map<pii,int>
#define all(a)                   (a).begin(),(a).end()
#define x                        first
#define y                        second
#define sz(x)                    (int)x.size()
#define endl                     '\n'
#define MOD                      1000000007
#define loop(i,a,b)              for(int (i)=(a);(i)<(b);(i)++)
#define rloop(i,a,b)             for(int (i)=(a);(i)>=(b);(i)--)
#define Unique(A)                (A).resize(distance((A).begin(),unique(all((A)))));
#define mxe(A)                   *max_element(all(A))
#define mne(A)                   *min_element(all(A))
#define debv(x)                  for(auto i : (x)) cout << i << ' ';cout << endl;
#define SP(x,y)                  cout << fixed << setprecision((y)) << (x) << endl;
#define setBits(x)               __builtin_popcountll(x)
#define zroBits(x)               __builtin_ctzll(x)
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define Max(x,y,z)               max(x,max(y,z))
#define Min(x,y,z)               min(x,min(y,z))
#define clr(x)                   memset(x,0,sizeof(x)) // not sure work for 2D arrya or not

template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

using namespace std;

char A[1100][1100];
ll dp[1100][1100];

int main(){
    dp[0][0] = 1;
    int a ,b ; cin >> a >> b ;
    loop(i,0,a) loop(j,0,b) cin >> A[i][j];
    loop(i,0,a) loop(j,0,b) {
        if(A[i][j]=='#') continue;
        if(i-1>=0) dp[i][j] = (dp[i-1][j]+dp[i][j])%MOD;
        if(j-1>=0) dp[i][j] = (dp[i][j-1]+dp[i][j])%MOD; 
    }
    cout << dp[a-1][b-1] << endl;
    return 0;
}

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

using namespace std;
const int MOD = 1000000007,MAX = 510000;
long int pow107 = (int)pow(10, 9) + 7,llimit = LONG_MAX,fac[MAX], finv[MAX], inv[MAX];
int ilimit = INT_MAX;

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long int COM(long int n,long int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

bool comp(pair<int, int> a, pair<int, int> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

long int Func2(long int n,long int m){
    long int s2 = 1,
        r = 1;
    for(long int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % (pow107);
    }
    return s2;
}

bool secsort(pair<int, int> a, pair<int, int> b){
    if(a.second == b.second)return a.first > b.first;
    else return a.second > b.second;
}

long int GCD(long int a,long int b){
    if(b == 0)return a;
    return GCD(b,a%b);
}

long int LCM(long int a,long int b){
    return a/GCD(a,b)*b;
}

//long intの最大llimit
//intの最大ilimit
//10^9+7    pow107
//素数pn
//n乗jou
//階乗factorial
//コンビネーションFunc2
//コンビネーションCOMinit(),COM(n,m)

int main(){
    int n ,k;
    cin >> n >> k;
    int a = 1,r;
    for(int i = 0; i < n; ++i){
        if(a > k){
            a += k;
        }else{
            a *= 2;
        }
    }
    cout << a << endl;
}

Measured memory_bytes: 256
#include<stdio.h>



main(){
	char c[1001];
int i;
int hoge=0;
	    while(1){
			scanf("%s",&c);
			if(c[0]=='0'){
				break;
			}
			
			for(i=0; c[i]!='\0'; i++){
				
			hoge += c[i]-'0';
			}
			
			printf("%d\n",hoge);
			hoge=0;
			
		   }

	return 0;
}

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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N,Z,W;
  cin>>N>>Z>>W;
  vector<ll> v(N);
  cinv(v,0,N);

  if(N>=2)cout<<max(abs(v[N-1]-W),abs(v[N-1]-v[N-2]))<<endl;
  else cout<<abs(v[N-1]-W)<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rei register int
using namespace std;
const int maxn = 2000010;
int min_prime[maxn],prime[maxn],tot;
int cnt[maxn];
void pre(){
	for(rei i = 2;i <= 1000000;++i){
		if(!min_prime[i]) prime[++tot] = i,min_prime[i] = i;
		for(rei j = 1;j <= tot && prime[j] <= min_prime[i] && 1ll*i * prime[j] <= 1000000;++j)
		min_prime[i * prime[j]] = prime[j];
 	}
}
int gcd(int x,int y){
	return y ? gcd(y,x % y) : x;
}
int main(){
	pre(); int n; cin >> n; int flag(1),g(0);
	for(rei i = 1;i <= n;++i) {
		int x ; scanf("%d",&x); g = gcd(x,g);
		while(x > 1){
			int d = min_prime[x]; if(cnt[d]) flag = 0;
			while(x % d == 0) x /= d; ++cnt[d];
		} 
	} if(flag) puts("pairwise coprime");
	else if(g == 1) puts("setwise coprime");
	else puts("not coprime"); return 0;
}

Measured memory_bytes: 11880
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;
const ll mod  = 1e9 + 7;
const int INF = 2e9;
using pint = pair <int, int>;

int main() {
  int a, b;
  cin >> a >> b;
  cout << a * b << endl;
  return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1e9;
const long double EPS = 1e-10;
const int MAX = 1e5;

struct Edge {
  int f, t, c;

  Edge(int f, int t, int c): f(f), t(t), c(c) {}
};

vector<Edge> G[MAX];
vector<int> d(MAX, INF);
bool visited[MAX];

void dijkstra(int u) {
  d[u] = 1;
  list<Edge> q;
  q.push_back(Edge(u, u, 0));
  while (!q.empty()) {
    Edge e = q.front();
    q.pop_front();
    if (visited[e.t]) continue;
    visited[e.t] = true;
    d[e.t] = d[e.f] + e.c;
    for (Edge f: G[e.t]) {
      if (f.c == 0) q.push_front(f);
      else if (f.c == 1) q.push_back(f);
    }
  }
}

int main() {
  int k;
  cin >> k;

  rep(i, k) G[i].push_back(Edge(i, (i + 1) % k, 1));
  rep(i, k) G[i].push_back(Edge(i, (i * 10) % k, 0));
  dijkstra(1);
  cout << d[0] << endl;




  
  return 0;
}

Measured memory_bytes: 10880
S = input()
last_ind = len(S)
yes = True
for i in range(len(S) - 1, -1, -1):
    if S[i:last_ind] == "dream" or S[i:last_ind] == "erase" or S[i:last_ind] == "eraser" or S[i:last_ind] == "dreamer":
        last_ind = i
        continue
    if last_ind - i > 7 or i == 0:
        yes = False
        break
        
if yes:
    print("YES")
else:
    print("NO")

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

int C[3][3];
int main(){
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin >> C[i][j];
		}
	}
	bool judge = true;
	for(int i=0;i<2;i++){
		if(!(C[0][i+1]-C[0][i] == C[1][i+1]-C[1][i] && C[1][i+1]-C[1][i] == C[2][i+1]-C[2][i])){
			judge = false;
		}
	}
	for(int i=0;i<2;i++){
		if(!(C[i+1][0]-C[i][0] == C[i+1][1]-C[i][1] && C[i+1][1]-C[i][1] == C[i+1][2]-C[i][2])){
			judge = false;
		}
	}
	if(judge) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    bool buy = false;
    for(int i = 0; i <= N/4; i++){
        for(int j = 0; j <= N/7; j++){
            if(4*i+7*j == N){
           buy = true;
            }
        }
        
    }
    if(buy == true)
    cout << "Yes" << endl;
    else if(buy == false)
    {
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

int main()
{
ll N, res = 1;
cin >> N;
for(int i = 1;i <= N;i++){
res = (res * i) % mod;
}
cout << res << endl;
}


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

int W, H;
char tile[25][25];
int cnt;
int x, y;

void dfs(int y, int x){
	tile[y][x] = '#';
	cnt++;
	int dy[4] = { 0, 1, 0, -1 };
	int dx[4] = { 1, 0, -1, 0 };
	for (int i = 0; i < 4; i++){
		int Y = y + dy[i];
		int X = x + dx[i];
		if (0 <= Y&&Y < H && 0 <= X&&X < W&&tile[Y][X] != '#'){
			dfs(Y, X);
		}
	}
}

int main(){

	while (cin >> W >> H, W != 0 && H != 0){
		for (int i = 0; i < H; i++){
			for (int j = 0; j < W; j++){
				cin >> tile[i][j];
				if (tile[i][j] == '@'){
					y = i;
					x = j;
				}
			}
		}
		dfs(y, x);
		cout << cnt << endl;
		cnt = 0;
	}

	return 0;
}


Measured memory_bytes: 3036
#include<bits/stdc++.h>
using namespace std;
int main(){ 
    int n,a,b,x,ans=0;
    scanf("%d %d %d",&n,&a,&b);
    while(n--){
        cin>>x;
        if(x<a||x>=b)ans++;
    }
    cout<<ans<<endl;
    return 0; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

const ll INF = 1e18;
const int MAX_N = 100050;
int n, m, s, t;
vector<pair<int, pair<ll, ll> > > adj[MAX_N];

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	cin >> n >> m >> s >> t;
	rep(i,0,m) {
		ll x, y, z, w;
		cin >> x >> y >> z >> w;
		adj[x].pb(mp(y,mp(z,w)));
		adj[y].pb(mp(x,mp(z,w)));
	}

	vl a(n+1, INF);
	priority_queue<pair<ll, int> > q;
	a[s] = 0;
	q.push(mp(0,s));
	while(!q.empty()) {
		int here = q.top().S;
		ll cost = -q.top().F;
		q.pop();
		if(cost > a[here]) continue;
		for(auto e : adj[here]) {
			int there = e.F;
			ll ncost = cost + e.S.F;
			if(a[there] > ncost) {
				a[there] = ncost;
				q.push(mp(-ncost, there));
			}
		}
	}

	vl b(n+1, INF);
	b[t] = 0;
	q.push(mp(0,t));
	while(!q.empty()) {
		int here = q.top().S;
		ll cost = -q.top().F;
		q.pop();
		if(cost > b[here]) continue;
		for(auto e : adj[here]) {
			int there = e.F;
			ll ncost = cost + e.S.S;
			if(b[there] > ncost) {
				b[there] = ncost;
				q.push(mp(-ncost, there));
			}
		}
	}

	vl ret(n,1e15);
	per(i,0,n) {
		if(i == n-1) {
			ret[i] = ret[i] - a[n] - b[n];
		} else {
			ll loc = 1e15 - a[i+1] - b[i+1];
			ret[i] = max(loc, ret[i+1]);
		}
	}
	rep(i,0,n) {
		cout << ret[i] << '\n';
	}
}

Measured memory_bytes: 13688
n, y = gets.chomp.split.map(&:to_i)

0.upto(n) do |i|
  0.upto(n-i) do |j|
    money = i * 10000 + j * 5000 + (n-i-j) * 1000
    if money == y
      puts [i, j, n-i-j].join(' ')
      exit
    end
  end
end

puts '-1 -1 -1'

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=998244353;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    ll n,zo=0;
    cin>>n;
    VL arr(n);
    map<ll,ll> mp;
    fr(i,0,n)
    {
        cin>>arr[i];
        if (i==0&&arr[i]!=0)
        {
            cout<<"0\n";
            return;
            /* code */
        }
        if(arr[i]==0)
            zo++;
        mp[arr[i]]+=1;
    }
    bool fg=false;
    ll last=0;
    if(zo!=1)
    {
        cout<<"0\n";
        return;
    }
    ll ans=1;
    fr(i,1,n)
    {
        if(!mp.count(i))
        {
            if(fg)
            {

            }
            else
            {
                fg=true;
            }
        }
        else
        {
            if(fg)
            {
                cout<<"0\n";
                return;
            }
            else
            {
                fr(j,0,mp[i])
                {
                    ans*=mp[i-1];
                    ans%=mod;
                }
            }
        }
    }
    cout<<ans<<endl;
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

Measured memory_bytes: 10224
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = MOD #出力の制限
N = 5*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N,K = MI()
ans = cmb(2*N-1,N-1,MOD)
if K<N-1:
    for i in range(K+1,N):
        ans -= cmb(N,i,MOD)*cmb(N-1,i,MOD)
print(ans%MOD)


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


int main(){
	int n,k;
	cin >> n >> k;
	vector<int> vec(n,0);
	for(int i=0;i<k;i++){
		int d;
		cin >> d;
		for(int j=0;j<d;j++){
			int a;
			cin >> a;
			vec.at(a-1)++;
		}
	}
	int ans=0;
	for(int i=0;i<n;i++){
		if(vec.at(i)==0){
			ans++;
		}
	}
	cout << ans << endl;
}


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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FILE_WR freopen("../input.txt", "r", stdin);\
	freopen("../output.txt", "w", stdout);
#define deb(x)	cout << #x << " " << x << endl;
#define ll long long int

int main() {

	//FILE_WR
	IOS

	int n, x, y;
	cin >> n >> x >> y;

	int dist[n+1][n+1] = {0};

	for (int i = 1; i <= n; i++) {
		for (int j = i+1; j <= n; j++) {
			dist[i][j] = dist[j][i] = abs(i-j);
		}
	}

	map<int, int> dist_count;
	for (int i = 1; i <= n; i++) {
		for (int j = i+1; j <= n; j++) {
			dist[i][j] = min(dist[i][j], dist[i][x] + dist[j][y] + 1);

			// deb(i); deb(j); deb(dist[i][j]); deb(dist[i][x]); deb(dist[j][y]);

			dist_count[dist[i][j]]++;
		}
	}

	for (int i = 1; i <= n-1; i++)
		cout << dist_count[i] << endl;
}

Measured memory_bytes: 16000
n, s = map(int, input().split())
xxx = [abs(s - y) for y in map(int, input().split())]
d = 0
while True:
    xxx = [x for x in xxx if x > 0]
    d = min(xxx)
    xxx = [x % d for x in xxx]
    if all(x == 0 for x in xxx):
        break
print(d)


Measured memory_bytes: 14224
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>

using namespace std;

int main(){
   int N;
   string A,B,C;
   cin >> N >> A >> B>>C;
   int ans = 0;
   for(int i = 0 ; i < N;i++){
      if(A[i]==B[i]&&B[i]==C[i]){
         // do nothing
      }
      else if(A[i]!=B[i]&&B[i]!=C[i]&&C[i]!=A[i]){
         ans += 2;
      }
      else{
         ans++;
      }
   }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)

int main(int argc, char** argv) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (argc == 2 && atoi(argv[1]) == 123456789)
        freopen("d:\\code\\cpp\\stdin", "r", stdin);

    int n;
    cin >> n;


    ll sum = 0;
    vector<int> a(n);
    FOR(i, n) {
        cin >> a[i];
        sum += a[i];
    }

    double avg = sum*1.0/n;

    double mdist = 1e9;
    int poz = -1;
    FOR(i, n){
        double dist = fabs(avg - a[i]);
        if (dist < mdist){
            mdist = dist;
            poz = i;
        }
    }
    cout << poz;
    return 0;
}

Measured memory_bytes: 892
s = input()
if s == "RRR":
  print(3)
if s == "SSS":
  print(0)
if s == "RRS":
  print(2)
if s == "SRR":
  print(2)
if s == "RSS":
  print(1)
if s == "SRS":
  print(1)
if s == "SSR":
  print(1)
if s == "RSR":
  print(1)

Measured memory_bytes: 9120
#include<iostream>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
string s;
int shua,shub,shuc; 
int main()
{
	cin>>s;
	for(int i=0;i<3;i++)
	{
		if(s[i]=='a')
			shua++;
		if(s[i]=='b')
			shub++;
		if(s[i]=='c')
			shuc++;
	}
	if(shua==1 && shub==1 &&shuc==1)
		cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
  	return 0;
}

Measured memory_bytes: 256
// finish date: 2018/05/13
#include <bits/stdc++.h>


using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>


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

    vc seq(N, '?');
    char which[] = {'S', 'W'};

    rep(i, 2) {
        rep(j, 2) {
            seq = vc(N, '?');
            seq[0] = which[i];
            seq[1] = which[j];
            bool con = ((seq[0] == 'S' && ((seq[1] == 'S' && s[0] == 'o') || (seq[1] == 'W' && s[0] == 'x')))
                        ||
                        (seq[0] == 'W' && ((seq[1] == 'S' && s[0] == 'x') || (seq[1] == 'W' && s[0] == 'o'))));
            seq[N - 1] = (con) ? 'S' : 'W';;

            int seq_first = seq[0];
            int seq_last = seq[N - 1];

            FOR(k, 1, N) {
                con = ((seq[k] == 'S' && ((seq[k - 1] == 'S' && s[k] == 'o') || (seq[k - 1] == 'W' && s[k] == 'x')))
                       ||
                       (seq[k] == 'W' && ((seq[k - 1] == 'S' && s[k] == 'x') || (seq[k - 1] == 'W' && s[k] == 'o'))));
                seq[(k + 1) % N] = (con) ? 'S' : 'W';
            }
            if (seq[0] == seq_first && seq[N - 1] == seq_last) {
                rep(i, N) {
                    cout << seq[i];
                }
                cout << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
	int H,W,i,j;
	for(;;){
		cin>>H>>W;
		if(H==0&&W==0){
			break;
		}
		for(i=1;i<=H;i++){
			for(j=1;j<=W;j++){

				if(i==1||i==H||j==1||j==W){
					cout<<"#";
				}
				else{
					cout<<".";
				}
			}
			cout<<endl;
		}
		cout<<endl;

	}
	return 0;
}

Measured memory_bytes: 3088