akhauriyash/Code-Regression huggingface dataset:
/*	AtCoder ARC 093 D Grid Components
	1st Edition:2018.3.24 Saturday
	Algorithm:Greedy
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <cctype>
using namespace std;

#define is_lower(c) (c>='a' && c<='z')
#define is_upper(c) (c>='A' && c<='Z')
#define is_alpha(c) (is_lower(c) || is_upper(c))
#define is_digit(c) (c>='0' && c<='9')
#define stop system("PAUSE")
#define ForG(i,a,b,c) for(rg int (i)=c.head[a],(b)=c.E[i].v;(i);(i)=c.E[i].nxt,(b)=c.E[i].v)
#define ForR(a,b,c) for(rg int (a)=b;(a)>=(c);--(a))
#define For(a,b,c) for(rg int (a)=(b);(a)<=(c);++a)
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define shl(x,y) ((x)<<(y))
#define shr(x,y) ((x)>>(y))
#define mp make_pair
#define pb push_back
#define rg register
#ifdef ONLINE_JUDGE
#define hash rename_hash
#define next rename_next
#define prev rename_prev
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef double db;
const ll inf=1000000007LL;
const db EPS=1e-14;
const ll inf_ll=(ll)1e18;
const ll maxn=105LL;
const ll mod=1000000007LL;

int A,B;
int n,m;
int g[maxn][maxn];

int main(){
	scanf("%d%d",&A,&B);
	n=m=100;
	For(i,1,n) For(j,1,m){
		if(2*j<=m) g[i][j]=0;
		else g[i][j]=1;
	}
	--A;--B;
	for(int i=1;2*i<=m;i+=2){
		if(!B) break;
		for(int j=1;j<=n && B;j+=2) g[j][i]=1,--B;
	}
	for(int i=m;i*2>m;i-=2){
		if(!A) break;
		for(int j=1;j<=n && A;j+=2) g[j][i]=0,--A;
	}
	printf("%d %d\n",n,m);
	For(i,1,n){
		For(j,1,m) putchar((g[i][j]?'#':'.'));
		puts("");
	}
	return 0;
}

Measured memory_bytes: 256
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let nm: Vec<usize> = read_vec();
    let n = nm[0];
    let m = nm[1];
    let abv: Vec<Vec<usize>> = read_vec2(m);

    let mut count: Vec<usize> = vec![0; n];

    for i in 0..m {
        let a = abv[i][0] - 1;
        let b = abv[i][1] - 1;
        count[a] += 1;
        count[b] += 1;
    }

    for i in 0..n {
        if count[i] % 2 == 1 {
            println!("NO");
            return;
        }
    }
    println!("YES");
    return;
}


Measured memory_bytes: 10492
s = input()
if len(s) % 2 != 0 or len(s) == 0:
    print("No")
else:
    for i in range(0, len(s), 2):
        if s[i] + s[i+1] == "hi":
            continue
        else:
            print("No")
            exit(0)
    print("Yes")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    ll ans=1;
    REP(i,n){
        if(ans>k) ans+=k;
        else ans*=2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::cmp::max;
fn main() {
    input! {
        n:i64,
        tan:[(i64,i64);n],
    }
    let mut ans = (1, 1);
    for &(t, a) in &tan {
        let sub = max((ans.0 + t - 1) / t, (ans.1 + a - 1) / a);
        ans = (sub * t, sub * a);
    }
    println!("{}", ans.0 + ans.1);
}

Measured memory_bytes: 4352
import java.util.*;

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

        String s = sc.next();
        System.out.print(s.charAt(0));
        System.out.print(s.length() - 2);
        System.out.print(s.charAt(s.length() - 1));
        System.out.println();

    }
}



Measured memory_bytes: 21844
#include<cstdio>
#include<cstring>
using namespace std;
char s[10];
int main(){
	scanf("%s",s);
	int ans=0,n=strlen(s);
	for (int i=0;i<n;i++) 
	if (s[i]=='+') ans++;else ans--;
	printf("%d",ans);
} 

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cctype>
#include <stdio.h>
using namespace std;

int main(){
  string a;

  int n[26];
  for(int i=0;i<26;i++){
    n[i] = 0;
  }

  while(cin >> a){
    for(int i=0;i<a.size();i++){
      if(isalpha(a[i])){
        if(isupper(a[i])){
          a[i] += 32;
        }
        for(int j=0;j<26;j++){
          if((a[i]-97)==j){
            n[j]++;
            break;
          }
        }
      }
    }
  }
  getline(cin,a);





  for(int i=0;i<26;i++){
    printf("%c : %d\n",i+97,n[i]);
    //cout << itoa(i+97) << " : " << n[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 3288
#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 REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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

template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
///////////////////////////////////////////////
/*（๑•﹏•๑｀) */


int main() {
	ll N;

	cin >> N;
	ll ans = 0;


	FORq(I,1,1e6 + 12){
		ll i = I;
		if (N % i == 0){
			ll m = N / i - 1;
			if (m <= i) break;
			if (N - i * m == i){
				ans += m;
			}


		}


	}


	cout << ans << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n, m, x;
    int a[100+5];
    scanf("%d %d %d", &n, &m, &x);
    for(int i=0; i<m; i++)scanf("%d", &a[i]);
    
    int ans=0;
    while(a[ans]<x)ans++;
    printf("%d\n", ans<m-ans ? ans: m-ans);
    return 0;
}


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

typedef long long ll;

ll ruijyo(ll a,ll n){
    if(n==0) return 1;
    ll x = ruijyo(a,n/2);
    x = x * x;
    if(n%2==1) x = x * a;
    return x;
}

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

    int x; cin >> x;
    ll ans = 1;
    for(int b=1;b<35;b++){
        for(int p=2;p<11;p++){
            ll uku = ruijyo((ll)b,(ll)p);
            if(uku<=x) ans = max(ans,uku);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from itertools import combinations
n,m = map(int,input().split())
l = []
for i in range(m):
    u = list(map(int,input().split()))
    u = u[1:]
    l.append(u)

p = list(map(int,input().split()))
v = []
for i in range(1,n+1):
    v.append(i)

c = []
for i in range(n+1):
    a = combinations(v,i)
    for k in a:
        c.append(k)

ans = 0
for ele in c:
    s = set(ele)
    f = 0
    for i in range(len(l)):
        x = l[i]
        cnt = 0
        for j in x:
            if j in s:
                cnt = cnt+1

        if cnt%2 != p[i]:
            f = 1
            break

    if f == 0:
        ans = ans+1

print(ans)

Measured memory_bytes: 9168
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<vector>

using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  for(int i = 0 ; i< n ; i++){
    cin >> d[i];
  }
  sort(d.begin(),d.end());
  cout << d[n/2] - d[n/2-1] << endl;
  return 0;
}

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

using namespace std;

char s[100005];
int main() {
    scanf("%s", s);
    int k;
    scanf("%d", &k);
    int n = strlen(s);
    for (int i = 0; i < n; ++i) {
        int req = 26 - (s[i] - 'a');
        if (req <= k && s[i] != 'a') s[i] = 'a', k -= req;
    }

    k %= 26;
    s[n - 1] += k;

    printf("%s\n", s);

    return 0;
}


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

#define mp make_pair

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef pair<i64,int> pli;
typedef pair<int,i64> pil;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;

template <typename T>
T id(T b) {return b;};
template <class It>
bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It>
bool any(It f,It l){return std::any_of(f,l,id<bool>);}

const int MAX_H = 200;
const int MAX_N = 10;
int h,w;
int a[MAX_H][MAX_H];
int c[MAX_N][MAX_N];

namespace warshall_floyd {
  const int64_t INF = 1000000000;
  int64_t d[MAX_N][MAX_N];
  int n;

  void init(int m)
  {
    n = m;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        d[i][j] = i == j ? 0 : INF;
  }

  void add_edge(int u, int v, int64_t cost)
  {
    d[u][v] = cost;
  }

  void calc()
  {
    for (int k = 0; k < n; k++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  }
}


int main()
{
  warshall_floyd::init(10);
  cin >> h >> w;
  int cost;
  for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++) {
      cin >> cost;
      warshall_floyd::add_edge(i, j, cost);
    }

  warshall_floyd::calc();

  int total = 0;
  int a;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> a;
      if (a >= 0)
        total += warshall_floyd::d[a][1];
    }
  }

  cout << total << endl;

  return 0;
}


Measured memory_bytes: 256
H,W=map(int,input().split())
A=[list(map(int,input().split())) for i in range(H)]
for i in range(H):
    B=list(map(int,input().split()))
    for j in range(W):
        A[i][j]=abs(A[i][j]-B[j])
D=80*(H+W)+1
D2=D*2
dp=[[0]*W for i in range(H)]
dp[0][0]|=1<<(D+A[0][0])
dp[0][0]|=1<<(D-A[0][0])
for i in range(H):
    for j in range(W):
        if i:
            dp[i][j]|=dp[i-1][j]<<A[i][j]
            dp[i][j]|=dp[i-1][j]>>A[i][j]
        if j:
            dp[i][j]|=dp[i][j-1]<<A[i][j]
            dp[i][j]|=dp[i][j-1]>>A[i][j]
res=dp[-1][-1]
ans=10**18
for i in range(D2):
    if res>>i&1:
        ans=min(ans,abs(D-i))
print(ans)

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

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;


int main(){
  string s;
  cin >> s;
  ll ans = 0;
  vector<ll> v;
  rep(i, s.size()){
    if(s[i] == 'W'){
      v.push_back(i);
    }
  }
  rep(i, v.size()){
    ans += v[i] - i;
    // cout << v[i] << ' ' << i << endl;
  }
  cout << ans << endl;
  
  return 0;
}


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

int main(){

  int N, ans;
  cin >> N;

  for(int i=0; i<10; i++){
    if(pow(2, i) > N){
      ans = pow(2, i-1);
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


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

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

    int pos_x = 0, pos_y = 0, now = 0;
    for(int i = 0; i < N; i++){
        int t, x, y;
        cin >> t >> x >> y;
        
        int time = t - now;
        int dist = abs(x - pos_x) + abs(y - pos_y);
        if(t < dist || (time - dist) % 2 != 0){
            cout << "No" << endl;
            return 0;
        }
        pos_x = x;
        pos_y = y;
        now += time;
    }  
    cout << "Yes" << endl;

    return 0;
}


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

#pragma warning(disable:4996)
using namespace std;
using ld=long double;
ld eps=1e-9;

string chs="RGW";

vector<pair<int,int>>getV(const vector<string>&sts, const int sum,int need) {
	int H(sts.size());
	int W(sts[0].size());

	vector<pair<int,int>>v;

	for (int y = 0; y < H; ++y) {
		int x=sum-y;
		if (!(x < 0 || x >= W)) {
			v.emplace_back(y,int(chs[need]==sts[y][x]));
		}
	}
	return v;
}

bool check(const vector<string>&sts,int y, int x, int H, int W,int need) { return 0 <= y && 0 <= x&&y < H&&x < W&&sts[y][x]==chs[need]; }
int dx[] = { -1,0,1,0 };
int dy[] = { 0,1,0,-1 };

int main() {
	int H,W;cin>>H>>W;
	vector<string>sts(H);
	for(int i=0;i<H;++i)cin>>sts[i];

	int answer=0;
	for (int i = 1; i < H + W -2 ; i = i + 1 ) {
		vector<pair<int,int>>vs=getV(sts,i,1);

		vector<vector<int>>dp(vs.size()+1,vector<int>(3));

		for (int j = 0; j < vs.size(); ++j) {
			pair<int,int> p(vs[j].first,i-vs[j].first);
			vector<pair<int,int>>dps(4);
			for (int k = 0; k < 4; ++k) {
				dps[k]=make_pair(p.first+dy[k],p.second+dx[k]);
			}
			if (check( sts, p.first, p.second, H, W, 1)) {
				if (check(sts, dps[0].first, dps[0].second, H, W, 0) && check(sts, dps[2].first, dps[2].second, H, W, 2)) {
					dp[j+1][0]=max(dp[j+1][0],1+max(dp[j][0],dp[j][2]));
				}
				if (check(sts, dps[3].first, dps[3].second, H, W, 0) && check(sts, dps[1].first, dps[1].second, H, W, 2)) {
					dp[j + 1][1] = max(dp[j + 1][1], 1+max(dp[j][1], dp[j][2]));
				}
			}
			dp[j+1][2]=max(dp[j+1][2],max(dp[j][0],max(dp[j][1],dp[j][2])));
			
		}
		int nanswer=max(dp[vs.size()][0],max(dp[vs.size()][1],dp[vs.size()][2]));
		answer+=nanswer;
	}
	cout<<answer<<endl;

	return 0;
} 


Measured memory_bytes: 24016
import numpy as np
n = int(input())
a =np.array([int(x) for x in input().split()])

money = 1000
stock = 0

for i in range(n-1):
    if a[i] < a[i+1]:
        stock += money//a[i]
        money %= a[i]
    elif a[i] > a[i+1]:
        money += a[i]*stock
        stock = 0

money += a[-1]*stock

print(money)

Measured memory_bytes: 26824
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=100+10;
const int inf=0x3f3f3f3f;
int n;
int Ans=inf;
char s[maxn];

inline void file() {
	freopen("AGC016A.in","r",stdin);
	freopen("AGC016A.out","w",stdout);
}

int main() {
//	file();
	scanf("%s",s+1); n=strlen(s+1);
	for (int c='a';c<='z';++c) {
		int pos=0,Max=0;
		For (i,1,n)
			if (s[i]==c) {
				chkmax(Max,i-pos-1); pos=i;
			}
		chkmax(Max,n-pos);
		if (pos) chkmin(Ans,Max);
	}
	printf("%d",Ans);
	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
i=1
if 0 in a:
    ans=0
else:
    while i<n:
        ans*=a[i]
        i+=1
        if ans>1000000000000000000:
            ans=-1
            break
print(ans)

Measured memory_bytes: 84732
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
n h w
a1 b1
...
an bn
 */
int n,h,w;

int main(){
  cin>>n>>h>>w;
  int ans=0;
  REP(i,n){
    int a,b;
    cin>>a>>b;
    if(a>=h && b>=w)
      ans++;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define m_k 9
int N,k,d[m_k];
int c(int a){
int i,j,p,l;
l=a;
while(l!=0){
p=l%10;
for(j=0;j<k;j++){
if(p==d[j])return 1;
}
l/=10;
}
return 0;
}
int main(){
int i;
scanf("%d%d",&N,&k);
for(i=0;i<k;i++){
scanf("%d",&d[i]);
}
i=N;
while(1){
if(c(i)==0)break;
else i++;
}
printf("%d\n",i);
}

Measured memory_bytes: 2124
// package app;

import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);

        // final String S = sc.next();
        final int A = sc.nextInt();
        final int B = sc.nextInt();
        final int X = sc.nextInt();

        System.out.println(A <= X && A + B >= X ? "YES" : "NO");

    }
}

Measured memory_bytes: 21844
#include <algorithm>
#include <bitset>
#include <boost/multiprecision/cpp_int.hpp>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#include<iomanip>
namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
using lll = boost::multiprecision::cpp_int;
using ll = long long;
#define FOR(i, N) for(ll i = 0; i < N; ++i)

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
// using int = ll;
ll gcd(ll m, ll n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
void swap(ll &a, ll &b) {
    ll tmp = a;
    a = b;
    b = tmp;
}
ll combi(ll n, ll k) {
    ll r = 1, rr = 1;
    for(ll i = 0; i < k; ++i) {
        r *= (n - i);
        rr *= (i + 1);
        // r %= 1000000007;
        // rr %= 1000000007;
    }
    r /= rr;
    // r %= 1000000007;
    return r;
}
int main() {
  ll N;
  cin>>N;
  vector<ll> D(N);
  FOR(i,N){
    cin>>D[i]; 
  }
  vector<ll> A(N+1,0);
  FOR(i,N){
    A[D[i]]++; 
  }
  if(A[0]!=1||D[0]!=0){
    cout<<0<<endl;
    return 0;
  }
  ll iii=0;
  ll ii=0;
  FOR(i,N+2){
    if(A[i]==0){
      break;
    }
    ii+=A[i];
    iii++;
  }
  if(ii!=N){
    cout<<0<<endl;
    return 0;
  }
  lll sum=1;
  for(int i=0;i<iii-1;++i){
    
    sum*=mp::pow(mp::cpp_int(A[i]),A[i+1])%998244353;
  }
  cout<<sum%998244353<<endl;
  return 0;
}


Measured memory_bytes: 2048
using System;
using System.Collections.Generic;
using System.Linq;

public class AtCoderA
{
    static void Main()
    {
        string s1 = Console.ReadLine();
        string s2 = Console.ReadLine();

        int answer = 0;
        for (int i = 0; i < 3; i++)
        {
            if (s1.Substring(i, 1).Equals(s2.Substring(i, 1)))
            {
                answer++;
            }
        }

        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
int main(){
	int x;
	while(cin>>x){
		int ans=0;
		for(int i=x;i<=600-x;i+=x){
			ans+=i*i*x;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <functional>
using namespace std;
typedef double W;

int n, m, p, a, b;
double t[10];
int x[900], y[900];
double z[900];

const int MAX_V = (1 << 8) * 30;
const W INF = 1e8;

struct edge {
	int to;
	W cost;
};
typedef pair<W, int> P;

vector<edge> G[MAX_V];
W d[MAX_V];


void dijkstra(int s) {
	priority_queue< P, vector<P>, greater<P> > que;
	fill(d, d + MAX_V, INF);
	d[s] = 0;
	que.push(P(0, s));
	while(!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		for(int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int v(int i, int j) {
	return i * 30 + j;
}

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

	while(cin >> n >> m >> p >> a >> b, n) {
		a--, b--;
		for(int i = 0; i < m; i++) {
			for(int j = 0; j < 1 << 8; j++) {
				G[v(j, i)].clear();
			}
		}
		for(int i = 0; i < n; i++) {
			cin >> t[i];
		}

		for(int i = 0; i < p; i++) {
			cin >> x[i] >> y[i] >> z[i];
			x[i]--, y[i]--;
			for(int j = 0; j < 1 << n; j++) {
				for(int k = 0; k < n; k++) {
					if(j & (1 << k)) {
						G[v(j, x[i])].push_back(edge{ v(j ^ (1 << k), y[i]), z[i] / t[k] });
						G[v(j, y[i])].push_back(edge{ v(j ^ (1 << k), x[i]), z[i] / t[k] });
					}
				}
			}
		}

		dijkstra(v((1 << n) - 1, a));

		double ans = INF;
		for(int i = 0; i < 1 << n; i++) {
			ans = min(ans, d[v(i, b)]);
		}
		if(ans == INF) {
			cout << "Impossible" << endl;
		}
		else {
			cout << setprecision(15) << ans << endl;
		}
	}
}

Measured memory_bytes: 24184
#include <stdio.h>
#define Nmax 10000
#define Qmax 500

char LinerSearch(int );
int S[Nmax],n;

int main(){
  int q,i;
  int T[Qmax];
  int sum=0;
  char ans;

  scanf("%d",&n);
  for(i=0 ; i<n ; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0 ; i<q ; i++){
    scanf("%d",&T[i]);
  }
  
  for(i=0 ; i<q ; i++){
    ans = LinerSearch(T[i]);
    if(ans == 'T') sum++;
  }

  printf("%d\n",sum);

  return 0;
}

char LinerSearch(int key){
  int i;

  for(i=0 ; i<n ; i++){
    if (S[i] == key) return 'T';
  }

  return 'F';
}

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

int main(){ 
    int a,b;
    char op;
    cin >> a >> op >> b;
    while(op!='?'){
    	if(op=='+'){
    		cout << a+b << endl;
		}else if(op=='-'){
    		cout << a-b << endl;
		}else if(op=='*'){
    		cout << a*b << endl;
		}else if(op=='/'){
    		cout << a/b << endl;
		}
		cin >> a >> op >> b;
	}
}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std ;
#define ll long long int 
#define m 1000000007
int main(){
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
	int n;
	cin >> n ;
	int arr[n][n] ;
	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < n ; j++)
			cin >> arr[i][j] ;
	}
	ll dp[(1<<n)] ={0};
	dp[0] = 1 ;
	for(int i = 0 ; i < (1<<n) - 1 ; i++){
		int cnt = 0 ;
		for(int j = 0 ;  j < n ; j++){
			if(i & (1<<j))
				cnt++ ;
		}
		// cout << i << " " << cnt << '\n';
		for(int j = 0 ; j < n ; j++){
			if(!(i&(1<<j)) && arr[cnt][j]){
				// cout << i << " " << j << '\n' ;
				dp[i|(1<<j)] += dp[i] ;
				dp[i | (1<<j)] %= m ;
			}
		}
	}
	cout << dp[(1<<n) -1] ;
}

Measured memory_bytes: 16640
#include<stdio.h>
long long a[2]={101,103};
long long M[2]={1e9+7,1e9+9};
long long d[2][300010],k[2][300010];
long long R=1,C=1,H[2000010],N[2000010],h[300010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]||N[H[a]]==N[H[b]]&&h[H[a]]<h[H[b]]?1:0;
}
//挿入関数
void hin(long long a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
void init(char *s){//!
  int i,j;
  for(i=0;i<2;i++){
    k[i][0]=1;
    d[i][0]=0;
    for(j=0;s[j];j++){
      d[i][j+1]=(d[i][j]*a[i]+(s[j]-'a'+1))%M[i];
      k[i][j+1]=(k[i][j]*a[i])%M[i];
    }
  }
}
long long getlr(int l,int r,int i){//!
  return (d[i][r]-(d[i][l]*k[i][r-l])%M[i]+M[i])%M[i];
}
void gets(char *s,int *h){
  int i,j;
  for(i=0;i<2;i++){
    h[i]=0;
    for(j=0;s[j];j++)h[i]+=k[i][j]*(s[j]-'0');
  }
}
int match(int l,int r,int *h){
  int i;
  for(i=0;i<2;i++){
    if(getlr(l,r,i)-h[i])return 0;
  }
  return 1;
}
int main(){
  int n=0,m,a,b,i,j,l=0,r=1;
  char s[300010],q[5];
  scanf("%*d %d %s",&m,s);
  init(s);//printf("%s\n",s);
  //for(i=0;s[i];i++)printf("%lld ",k[0][i+1]);printf("\n");
  //printf("%lld %lld %lld\n",d[0][3],d[0][4],k[0][2]);return 0;
  //printf("%lld %lld\n",getlr(0,2,0),getlr(2,4,0));return 0;
  for(i=0;i<m;i++){
    scanf("%s",q);
    if(q[0]=='L')l+=q[1]-'-'?1:-1;
    else         r+=q[1]-'-'?1:-1;//printf("%d %d!",l,r);
    h[R]=getlr(l,r,0);
    hin(getlr(l,r,1));//printf("%lld %lld\n",h[R-1],N[R-1]);
  }
  a=hout();
  for(i=1;i<m;i++){
    b=hout();//printf("%lld %lld %lld %lld\n",N[a],N[b],h[a],h[b]);
    if(N[b]==N[a]&&h[b]==h[a])n++;
    a=b;
  }
  printf("%d\n",m-n);
  return 0;
}



Measured memory_bytes: 18556
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define rep(i, s, n) for (int i = s; i < (int)(n); i++)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int INF = 1e9;
struct edge
{
    int to;
    int cost;
};
P dp[310][310];
vector<edge> v[310];
int main()
{
    int n, m, l;
    cin >> n >> m >> l;
    REP(i, m)
    {
        int a, b, c;
        cin >> a >> b >> c;
        v[a].push_back(edge{b, c});
        v[b].push_back(edge{a, c});
    }
    // ダイクストラをｎ回やる
    // dp[s][t] ｓからスタートした結果
    for (int k = 0; k < n + 1; k++)
    {
        priority_queue<P, vector<P>, greater<P>> que;
        for (int j = 0; j <= n; j++)
        {
            dp[k][j] = P(INF, 0);
        }
        dp[k][k] = P(0, l);
        que.push(P(0, k));
        while (!que.empty())
        {
            P p = que.top();
            que.pop();
            int id = p.second;
            if (dp[k][id].first < p.first)
                continue;
            for (int i = 0; i < v[id].size(); i++)
            {
                edge e = v[id][i];
                //まじめに遷移を書く
                int d = 0;
                int cost = dp[k][id].second;
                if (e.cost > l)
                {
                    continue;
                }
                else if (e.cost > dp[k][id].second)
                {
                    d = 1;
                    cost = l;
                }
                if (dp[k][e.to].first > dp[k][id].first + d)
                {
                    dp[k][e.to] = P(dp[k][id].first + d, cost - e.cost);
                    que.push(P(dp[k][e.to].first, e.to));
                }
                else if (dp[k][e.to].first == dp[k][id].first + d && dp[k][e.to].second < cost - e.cost)
                {
                    dp[k][e.to] = P(dp[k][id].first + d, cost - e.cost);
                    que.push(P(dp[k][e.to].first, e.to));
                }
            }
        }
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        int s, t;
        cin >> s >> t;
        if (dp[s][t].first == INF)
        {
            cout << -1 << endl;
        }
        else
        {
            cout << dp[s][t].first << endl;
        }
    }
}


Measured memory_bytes: 2432
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


s = int(input())
li = [0 for i in range(10**7)]
li[s] = 1

ans = 1
while(1):
    ans += 1
    if s%2==0:
        s = s//2
    else:
        s = 3*s+1
    
    if li[s] == 1:
        print(ans)
        break
    else:
        li[s] = 1
    






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

typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
 
using namespace std;

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

    for(int i = 0; i < k ;i++){
        if(s[i] != '1') {
            cout << s[i] << endl;
            return 0;
        }
    }
cout << '1' << endl;
            

    
    return 0;
}


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

int main(){
	int N;
	cin >> N;
	
	int i, a[N/2], j=0, k, count1/*調べてる数の約数*/, count2/*該当する数(8つ約数)の量*/=0;
	for(i=1; i<=N; ){
		a[j]=i;
		count1=0;
		for(k=0; k<=j; k++){
			if(i%a[k]==0)	count1++;
		}
		if(count1==8)	count2++;
		j++;
		i += 2;
	}
	
	cout << count2 << endl;
	return 0;
}


Measured memory_bytes: 256
g=gets,k=(0..1e5).map{[]};$<.map{|l|a,b=l.split.map &:to_i;k[a]<<b;k[b]<<a};q=g[j=k[i=1][0]]=1,j;q[S,0]=g[R]=R while S=[0,i+=1].find{|c|R=k[q[-c/i]].find{|x|!g[x]}};puts i,q

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

using namespace std;

typedef long long ll;

const long long MOD = 1e9;

int main() {
  int N;
  cin >> N;
  vector<int> h(N);
  for (int i = 0; i < N; ++i) cin >> h[i];
  int res = 0;
  while (true) {
    int i = 0;
    while (i < N && h[i] == 0) i++;
    if (i == N) break;
    for (; i < N; ++i) {
      if (h[i] == 0) break;
      else h[i]--;
    }
    res++;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 1; i < n; i++) {
    int x;
    cin >> x;
    x--;
    a[x]++;
  }
  for (int i = 0; i < n; i++) {
    cout << a[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3984
N, M = map(int, input().split())

# 約数の全列挙
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort(reverse=True)  # ソート
    return divisors

for k in divisors(M):
    if k * N <= M:
        print(k)
        exit()

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>


int main()
{
    int n;
    std::cin >> n;
    int count = 0;
    for (int a = 1; a < n; a++)
    {
        for (int b = 1; b <= (n - 1 )/ a; b++)
        {
            count += 1;
        }
    }
    std::cout << count<< std::endl;
}

Measured memory_bytes: 3536
N,C = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(N)]

csum_r = [0]
cmax_r1 = [0]
cmax_r2 = [0]
for x,v in src:
    csum_r.append(csum_r[-1] + v)
    cmax_r1.append(max(cmax_r1[-1], csum_r[-1] - x))
    cmax_r2.append(max(cmax_r2[-1], csum_r[-1] - 2*x))

csum_l = [0]
cmax_l1 = [0]
cmax_l2 = [0]
for x,v in reversed(src):
    x = C-x
    csum_l.append(csum_l[-1] + v)
    cmax_l1.append(max(cmax_l1[-1], csum_l[-1] - x))
    cmax_l2.append(max(cmax_l2[-1], csum_l[-1] - 2*x))

ans = max(cmax_r1[-1], cmax_l1[-1])
for a,b in zip(cmax_r2, cmax_l1[::-1]):
    ans = max(ans, a+b)
for a,b in zip(cmax_l2, cmax_r1[::-1]):
    ans = max(ans, a+b)

print(ans)

Measured memory_bytes: 39412
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			char[] s = in.nextString().toCharArray();
			int ans = 700;
			for (int i = 0; i < s.length; i++) {
				if (s[i] == 'o') {
					ans += 100;
				}
			}
			out.println(ans);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 21332
n=int(input())
s = list(map(int,input().split()))
d = 0
c = n
while c == n:
    c = 0
    for i in range(0,n):
        if s[i]%2 == 0:
            s[i]=s[i]//2
            c += 1
    if c == n:
        d += 1
print(d)

Measured memory_bytes: 3060
from bisect import bisect_right
from sys import setrecursionlimit

setrecursionlimit(10**8)
n = int(input())
A = list(map(int, input().split()))
gr = []
for i in range(n):
    gr.append([])
for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    gr[a].append(b)
    gr[b].append(a)
ans = [0] * n
dp = [10 ** 10 for i in range(1 + n)]
dp[0] = -10 ** 10
kek = 1
used = {0}


def dfs(v):
    global kek
    j = bisect_right(dp, A[v] - 1)
    old = dp[j]
    if dp[j - 1] < A[v] < dp[j]:
        old = dp[j]
        dp[j] = A[v]
        if kek == j:
            for h in range(kek + 1, 1 + n):
                if dp[h] == 10 ** 10:
                    kek = h
                    break
            if kek == j:
                kek = n + 1
    ans[v] = kek - 1
    for u in gr[v]:
        if u not in used:
            used.add(u)
            dfs(u)
    dp[j] = old
    if kek > j and old == 10 ** 10:
        kek = j


dfs(0)
print(*ans)

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

def main():
    input_num = input()
    sum_num = 0

    for i in range(len(input_num)):
        chushutsu = int(input_num[i])
        sum_num += chushutsu
    
    if sum_num % 9 == 0:
        print('Yes')

    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 9244
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define int long long
#define rep(i, a, b) for (ll i = (a); i <= (b); ++i)
#define per(i, a, b) for (ll i = (a); i >= (b); --i)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (ll i = head[x]; i; i = edge[i].nex)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, cnt) memset(a, cnt, sizeof(a))
#define cop(a, b) memcpy(a, b, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast <t> (x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter putchar('\n')
#define siz(x) ((ll)x.size())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef double db ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <ll, ll> pii ;
typedef vector <ll> vi ;
typedef vector <pii> vii ;
typedef queue <ll> qi ;
typedef queue <pii> qii ;
typedef set <ll> si ;
typedef map <ll, ll> mii ;
typedef map <string, ll> msi ;
const ll maxn = 2e6 + 100 ;
const ll inf = 0x3f3f3f3f ;
const ll iinf = 1 << 30 ;
const ll linf = 2e18 ;
const ll mod = 998244353 ;
const double eps = 1e-7 ;
template <class T = ll> T chmin(T &a, T b) { return a = min(a, b);}
template <class T = ll> T chmax(T &a, T b) { return a = max(a, b);}
template <class T = ll> T read()
{
	T f = 1, a = 0;
	char ch = getchar() ;
	while (!isdigit(ch)) { if (ch == '-') f = -1 ; ch = getchar() ; }
	while (isdigit(ch)) { a =  (a << 3) + (a << 1) + ch - '0' ; ch = getchar() ; }
	return a * f ;
}

ll n;

ll x[maxn];

ll ans[maxn], l, r;

pqueue <pii, vii, greater <pii> > q1;

pqueue <pii> q2;

#define shit return puts("No"), 0

signed main()
{
	n = read();
	l = 1, r = n * n;
	rep(i, 1, n) x[i] = read(), q1.push(mp(x[i], i)), q2.push(mp(x[i], i)), ans[x[i]] = i;
	// puts("pre");
	rep(i, 1, n)
	{
		ll now = q1.top().se;
		q1.pop();
		ll tmp = now - 1;
		// printf("now : %lld\n", now);
		while(tmp)
		{
			if(!ans[l]) tmp --, ans[l] = now;
			l ++;
		}
		// printf("l : %lld\n", l);
		if(l > x[now]) shit;
	}
	// puts("suf");
	rep(i, 1, n)
	{
		ll now = q2.top().se;
		q2.pop();
		ll tmp = n - now;
		// printf("now : %lld\n", now);
		while(tmp)
		{
			if(!ans[r]) tmp --, ans[r] = now;
			r --;
		}
		// printf("r : %lld\n", r);
		if(r < x[now]) shit;
	}
	puts("Yes");
	rep(i, 1, n * n) printf("%lld%c", ans[i], " \n"[i == n * n]);
	return 0;
}

Measured memory_bytes: 5248
// khodaya khodet komak kon
#include <bits/stdc++.h>
#define pb push_back
#define ers erase
#define ins insert
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
#define kill(x) return cout << x, 0;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpl;

const ld Pi = 3.14159265359;
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll N = 2e5 + 10;
const ll INF = 1e18;
const ll LOG = 20;

ll H, W, a[N], ans[110][110];

int main(){
	IOS;
	cin >> H >> W;
	ll t;
	cin >> t;
	for (int i = 1; i <= t; i++) cin >> a[i];
	ll x = 1, y = 1;
	ll pnt = 1;
	ll f = 1;
	for (int i = 1; i <= H * W; i++){
		if (a[pnt] == 0) pnt++;
		//cout << x << ' ' << y << '\n';
		ans[y][x] = pnt;
		a[pnt] --;
		if (x == W && f == 1 || x == 1 && f == -1){
			f *= -1;
			y ++;
			//cout << '\n';
		}else{
			x += f;
			//cout << ' ';
		}
	}
	
	for (int i = 1; i <= H; i++){
		for (int j = 1; j <= W; j++){
			cout << ans[i][j] << ' ';
		}
		cout << '\n';
	}
	
	
	
	return 0;
}






/*
     ,---,           ___                 ,--,
    '  .' \        ,--.'|_             ,--.'|                             ,--,
   /  ;    '.      |  | :,'            |  | :                           ,--.'|    ,---.        ,---,
  :  :       \     :  : ' :            :  : '                 .--.--.   |  |,    '   ,'\   ,-+-. /  |
  :  |   /\   \  .;__,'  /    ,--.--.  |  ' |     ,--.--.    /  /    '  `--'_   /   /   | ,--.'|'   |
  |  :  ' ;.   : |  |   |    /       \ '  | |    /       \  |  :  /`./  ,' ,'| .   ; ,. :|   |  ,"' |
  |  |  ;/  \   \:__,'| :   .--.  .-. ||  | :   .--.  .-. | |  :  ;_    '  | | '   | |: :|   | /  | |
  '  :  | \  \ ,'  '  : |__  \__\/: . .'  : |__  \__\/: . .  \  \    `. |  | : '   | .; :|   | |  | |
  |  |  '  '--'    |  | '.'| ," .--.; ||  | '.'| ," .--.; |   `----.   \'  : |_|   :    ||   | |  |/
  |  :  :          ;  :    ;/  /  ,.  |;  :    ;/  /  ,.  |  /  /`--'  /|  | '.'\   \  / |   | |--'
  |  | ,'          |  ,   /;  :   .'   \  ,   /;  :   .'   \'--'.     / ;  :    ;`----'  |   |/
  `--''             ---`-' |  ,     .-./---`-' |  ,     .-./  `--'---'  |  ,   /         '---'
                            `--`---'            `--`---'                 ---`-'
*/




Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(i,n) rep2(i,0,n)
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n)cin >> h[i];
    int ans=0,cnt=0;
    rep(i,n-1){
        if(h[i]>=h[i+1])++cnt;
        else{
            ans=max(ans,cnt);
            cnt=0;
        }
    }
    ans=max(ans,cnt);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int red = 0;
		char a = 'R';
		sc.nextLine();
		String str = sc.nextLine();
		for (char x : str.toCharArray()) {
			if (x == a) {
				red++;
			} else {
				red--;
			}
		}
		if (red > 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		sc.close();
	}
}

Measured memory_bytes: 21588
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;

const int INF = 100000000;

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

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




int main(){
  int n;
  cin >> n;
  vector<vector<int> > to(n), cost(n);
  rep(i, n - 1){
    int a, b, w;
    cin >> a >> b >> w;
    a--;
    b--;
    to[a].push_back(b); cost[a].push_back(w);
    to[b].push_back(a); cost[b].push_back(w);
  }

  vector<int> ans(n, -1);
  queue<int> q;

  ans[0] = 0;
  q.push(0);

  while(!q.empty()){

    int v = q.front();
    q.pop();
    rep(i, to[v].size()){
      int u = to[v][i];
      int w = cost[v][i];
      if(ans[u] != -1) continue;
      ans[u] = (ans[v] + w) % 2;
      q.push(u);
    }
  }

  rep(i, n){
    cout << ans[i] << endl;
  }

}


Measured memory_bytes: 11904
#include <bits/stdc++.h>
#define int long long
using namespace std;

int isPrime(int x){
  
  if( x == 1 ) return true;
  
  for(int i=2;i*i<=x;i++){
    if( x % i == 0 ) return false;
  }

  return true;
}

signed main(){
  
  int a, b;
  cin>>a>>b;
  
  if( a > b ) swap( a, b );
  
  int A = __gcd( a, b );
  
  int ans = 0;
  
  for(int i=1;i*i<=A;i++){
    
    if( A % i ) continue;
    
    ans += isPrime( i );
    
    if( i*i == A ) continue;
    
    ans += isPrime( A / i );
    
  }
  
  cout<<ans<<endl;
    
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SORT(x) sort(rng(x))
#define RSORT(x) sort(rrng(x))
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

using T = tuple<ll, int, int, int>;

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

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 x, y, z;
  int K;
  cin >> x >> y >> z;
  cin >> K;
  vll a(x), b(y), c(z);

  rep(i,x) cin >> a[i];
  rep(i,y) cin >> b[i];
  rep(i,z) cin >> c[i];

  RSORT(a);
  RSORT(b);
  RSORT(c);

  priority_queue<T> pq;
  pq.push((make_tuple(a[0]+b[0]+c[0],0,0,0)));

  set<int> s;
  s.insert(0);

  vll ans;
  while (ans.size() < K) {
    auto v = pq.top(); pq.pop();
    ans.pb(get<0>(v));

    if (get<1>(v) != x-1) {
      int an = get<1>(v) + 1;
      int bn = get<2>(v);
      int cn = get<3>(v);
      // hashを作る
      int hash = (an << 20) + (bn << 10) + cn;
      if (s.find(hash) == s.end()) {
        s.insert(hash);
        pq.push((make_tuple(a[an]+b[bn]+c[cn],an,bn,cn)));
      }
    }
    if (get<2>(v) != y-1) {
      int an = get<1>(v);
      int bn = get<2>(v) + 1;
      int cn = get<3>(v);
      // hashを作る
      int hash = (an << 20) + (bn << 10) + cn;
      if (s.find(hash) == s.end()) {
        s.insert(hash);
        pq.push((make_tuple(a[an]+b[bn]+c[cn],an,bn,cn)));
      }
    }
    if (get<3>(v) != z-1) {
      int an = get<1>(v);
      int bn = get<2>(v);
      int cn = get<3>(v) + 1;
      // hashを作る
      int hash = (an << 20) + (bn << 10) + cn;
      if (s.find(hash) == s.end()) {
        s.insert(hash);
        pq.push((make_tuple(a[an]+b[bn]+c[cn],an,bn,cn)));
      }
    }
  }

  rep(i,K) {
    printf("%lld\n", ans [i]);
  }
  
  return 0;
}

Measured memory_bytes: 896
package main

import "fmt"

func main() {
  var N,ans int
  var countR,countG,countB int
  var S string
  fmt.Scan(&N)
  fmt.Scan(&S)

  for i:=0; i<N; i++{
    if S[i] == 82{
      countR++
    }
    if S[i] == 71{
      countG++
    }
    if S[i] == 66{
      countB++
    }
  }
  ans = countR*countG*countB
  
  for i := 0; i<N-2; i++ {
    for j := i+1; j<N-1; j++ {
      k := 2*j-i
      if k>=N{
        continue
      }
      if S[i]!=S[j] && S[j]!=S[k] && S[k]!=S[i]{
        ans--
      }
    }
  }
  fmt.Println(ans)
}


Measured memory_bytes: 1820
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <utility>
using namespace std;

template <typename T>
void print_vec(const vector<T> &v) {
  int n = v.size();
  for (int i = 0; i < n; ++i) {
    if (i > 0) cout << ' ';
    cout << v[i];
  }
  cout << '\n';
}

int main() {
  int x;
  cin >> x;
  if (x >= 30) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }

  return 0;
}


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

const int MXN=200005;
int n,h[MXN],a[MXN];

ll ft[MXN];
void upd(int x,ll v){
  for(;x<MXN;x+=x&-x)ft[x]=max(ft[x],v);
}
ll get(int x){
  ll ret=0;
  for(;x;x-=x&-x)ret=max(ret,ft[x]);
  return ret;
}

int main(){
  scanf("%d",&n);
  for(int i=0;i<n;++i)scanf("%d",h+i);
  for(int i=0;i<n;++i)scanf("%d",a+i);
  for(int i=0;i<n;++i)upd(h[i],get(h[i])+a[i]);
  printf("%lld\n",get(n));
}


Measured memory_bytes: 3328
# 2019/07/02
# かんにんぐあり

s=input()
t=input()

len_s=len(s)
len_t=len(t)

ans=[]

for i in range(len_s-len_t+1):
    flag=True
   # if s[i]==t[0]:
    for j in range(len_t):
        if s[i+j]==t[j] or s[i+j]=='?':continue
        else:
            flag=False
            break
    if flag:
        ans.append((s[:i]+t[:]+s[len_t+i:]).replace('?','a'))

ans.sort()
if len(ans)==0:print('UNRESTORABLE') 
else:print(ans[0])

Measured memory_bytes: 3064