akhauriyash/Code-Regression huggingface dataset:
#from math import sqrt
#from heapq import heappush, heappop
#from collections import deque
from functools import reduce

#a, b = [int(v) for v in input().split()]


def main():

    n, a, b = map(int, input().split())
    mod = 1000000007

    def pow(n, r):
        if r == 0:
            return 1
        val = pow(n, r // 2)
        val = val * val % mod
        if r % 2 == 1:
            val = val * n % mod
        return val

    def comb(n, r):
        over = 1
        under = 1
        for i in range(r):
            over = over * (n - i) % mod
            under = under * (i + 1) % mod

        return over * pow(under, mod - 2) % mod

    ans = pow(2, n) - 1 - comb(n, a) - comb(n, b) % mod
    while ans < 0:
        ans += mod
    print(ans)


main()


Measured memory_bytes: 3572
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
 	if(X == 7){
	System.out.println("YES");
    }else if(X == 5){
	System.out.println("YES");
    }else if(X == 3){
	System.out.println("YES");
    }else {
	System.out.println("NO");      
    }
}
    }

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

using namespace std;

int main(){
    long a;
    int n;
    long sum;
    vector<long> v;

    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> a;
        v.push_back(a);
    }
    sum = accumulate(v.begin(), v.end(), 0.0);
    cout << *min_element(v.begin(), v.end()) << " " << *max_element(v.begin(), v.end()) << " " << sum << endl;

    return 0;
}


Measured memory_bytes: 3268
from collections import Counter


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
    N, P = map(int, input().split())
    ps = prime_factorize(P)
    c = Counter(ps)

    ans = 1
    for key, val in c.items():
        times = val // N
        if times:
            ans *= key ** times
    print(ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<map>
using namespace std;

int main(void)
{
	int N;
	long long K;
	cin >> N >> K;

	map<int, long long> table;
	for(int i=0; i<N; i++)
	{
		int a, b;
		cin >> a >> b;

		table[a] += b;
	}

	int ret;
	long long k = K;
	for(auto it=table.begin(); it!=table.end(); it++)
	{
		if(k > it->second)
			k -= it->second;
		else
		{
			ret = it->first;
			break;
		}
	}

	cout << ret << endl;

	return 0;
}


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

/*
 b
lurd
 f
*/
struct Dice {
  long long l, r, f, b, d, u, x, y;
  Dice(long long _l = 4, long long _r = 3, long long _f = 2,
       long long _b = 5, long long _d = 6, long long _u = 1,
       long long _x = 0, long long _y = 0)
      : l(_l), r(_r), f(_f), b(_b), d(_d), u(_u), x(_x),
        y(_y) {}

  void RollN() {
    long long buff = d;
    d = b;
    b = u;
    u = f;
    f = buff;
    ++y;
  }

  void RollS() {
    long long buff = d;
    d = f;
    f = u;
    u = b;
    b = buff;
    --y;
  }

  void RollE() {
    long long buff = d;
    d = r;
    r = u;
    u = l;
    l = buff;
    ++x;
  }

  void RollW() {
    long long buff = d;
    d = l;
    l = u;
    u = r;
    r = buff;
    --x;
  }

  void RollL() {
    long long buff = f;
    f = l;
    l = b;
    b = r;
    r = buff;
  }

  void RollR() {
    long long buff = f;
    f = r;
    r = b;
    b = l;
    l = buff;
  }

  vector<Dice> makeDice() {
    vector<Dice> ret;
    for(int i = 0; i < 6; i++) {
      Dice d(*this);
      if(i == 1) d.RollN();
      if(i == 2) d.RollS();
      if(i == 3) d.RollS(), d.RollS();
      if(i == 4) d.RollE();
      if(i == 5) d.RollW();
      for(int j = 0; j < 4; j++) {
        ret.emplace_back(d);
        d.RollL();
      }
    }
    return (ret);
  }
};
long long a, b, c, d, e, f, q;
Dice die;
vector<Dice> v;

int main() {
  cin >> a >> b >> c >> d >> e >> f >> q;
  die = Dice(d, c, b, e, f, a);
  v = die.makeDice();
  for(int t = 0; t < q; ++t) {
    cin >> a >> b;
    for(int i = 0; i < 24; ++i)
      if(v[i].u == a && v[i].f == b) cout << v[i].r << endl;
  }
  return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<ll,ll>;
#define For(i,a,b)  for(int i=a;i<=b;i++)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
#define F first
#define S second
#define int ll
#define sz(x) ((ll)x.size())
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define mkp make_pair
#define INF (ll)(1e17)
#define MOD (ll)(998244353)

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	//I won't misunderstand the problem statement anymore.
	//I won't misunderstand the problem statement anymore.
	//I won't misunderstand the problem statement anymore.
	//I won't misunderstand the problem statement anymore.
	//I won't misunderstand the problem statement anymore.
	//I won't misunderstand the problem statement anymore.
	//I won't misunderstand the problem statement anymore.
	//I won't misunderstand the problem statement anymore.
	//I won't misunderstand the problem statement anymore.
	//I won't misunderstand the problem statement anymore.
	string s; cin>>s;
	if(s.back()=='s') s+='e';
	s+='s';
	cout<<s<<"\n";
	return 0;
}























Measured memory_bytes: 3564
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		// 入力
		int n = sc.nextInt();
		int t = sc.nextInt();

		int tmp = 9999;
		int min = 9999;
		int[] ci = new int[n];
		int[] ti = new int[n];
		int i = 0;
		for (i = 0; i < n; i++){
			ci[i] = sc.nextInt();
			ti[i] = sc.nextInt();
			if (ti[i] <= t){
				tmp = ci[i];
				if (min > tmp){
					min = tmp;
				}
			}
		}

		// 出力
		if (min < 9999){
			System.out.println(min);
		} else {
			System.out.println("TLE");
		}
	}
}

Measured memory_bytes: 22612
#include<iostream>
#include<string.h>
using namespace std;

class Game{
	int flag;
	int point;
	int out;
	int count;
	char sta[10];

public:
	int IN(const char *);
	int OUT();
	void Reset();
};

int Game::IN(const char *str){
	if(strcmp("HIT",str) == 0){
		if(count < 3)count++;
		else point++;
	}
	else if(strcmp("HOMERUN",str) == 0){
		point += count + 1;
		count = 0;
	}
	else{
		out++;
		if(out >= 3){
			flag++;
			return flag;
		}
	}
	return 0;
}

int Game::OUT(){
	return point;
}
void Game::Reset(){
	flag = 0;
	point = 0;
	out = 0;
	count = 0;
}


int main(){
	int i,f,set = 0;
	int po[50];
	char sta[10];
	Game ini;

	cin >> set;

	for(i = 0; i < set; i++ ){
		ini.Reset();
		f = 0;
		while(1){
			cin >> sta;
			f = ini.IN(sta);
			if(f == 1)break;
		}
		po[i] = ini.OUT();

	}

	for(i = 0; i < set ; i++)
		cout << po[i] << endl;

	return 0;
}

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

int main() {
  long long int n,a,b;
  cin >> n >> a >> b;
  if (n == 1) {
    if (a == b) {
      cout << 1 << endl;
    }
    else {
      cout << 0 << endl;
    }
  }
  else if (a > b){
    cout << 0 << endl;
  }
  else {
    cout << b*(n-2)-a*(n-2)+1<< endl;
  }
}

Measured memory_bytes: 3612
import sys

n, *a = map(int, sys.stdin.read().split())

def main():
    for i in range(n):
        a[i] -= (i + 1)
    a.sort()
    b = a[n // 2]
    res = 0
    for i in range(n):
        res += abs(a[i] - b)
    
    return res
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 25180
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,k = li()

# aをbin文字列で、bを数値で管理する
alis = []
blis = []
for _ in range(n):
    a,b = li()
    if a <= k:
        alis.append(a)
        blis.append(b)

binn = len(bin(k))-2
bink = bin(k)[2:]
binas = [bin(ai)[2:].zfill(binn) for ai in alis]


# binの候補を挙げる
cands = [bink]
for i, s in enumerate(list(bink)):
    if int(s):
        cands.append(bink[:i] + "0" + "1"*(binn-i-1))
        
ans = 0
for cand in cands:
    tmp = 0    
    cand = int("0b"+cand, 0)
    
    for a, b in zip(alis, blis):

        if cand | a <= cand:
            tmp += b
                
    ans = max(ans, tmp)
    
print(ans)

Measured memory_bytes: 19888
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int MAX = 510000;
const double pi=acos(-1);

int main(){
  int n;
  cin >> n;
  vector<pair<ll,ll>>vec;
  rep(i,n){
    ll a,b;
    cin >> a >> b;
    vec.push_back(make_pair(a,b));
  }
  sort(vec.begin(),vec.end(),greater<pair<ll,ll>>());
  cout << vec[0].first+vec[0].second << endl;
  return 0;
}


Measured memory_bytes: 2420
//This is getting accepted!
#include<bits/stdc++.h>
#define ll long long
#define oo 1000000009
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define INA(a,n) for (int i = 1; i <= (n); ++i) cin >> a[i];
#define ITE(x) for(auto it = (x).begin(); it != (x).end(); ++it)
#define isset(x, i) (((x)>>(i))&1)
#define setbit(x, i) ((x)^(1ll<<(i)))
#define clearbit(x, i) ((x)&(~(1ll<<(i))))
#define twoexp(i) (1ll<<(i))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) >= 0 ? (a) : -(a))
#define FI first
#define SE second
#define son1 (id*2)
#define son2 (id*2+1)

using namespace std;

const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = 2 * acos(0);
const int MAXN = 1e6 + 6;

int n;
int a[MAXN];

void input() {
	int u, v, w, x, y, qtype;
	
	cin >> n;
	INA(a, n);
	
	
}


void preprocess() {
	
	sort(a+1, a + n + 1);
	
}

void process(int itest) {
	int u, v, w, x, y, qtype;
	
	cout << a[n/2+1] - a[n/2] << endl;
	
}

void oneTest() {
	
	input();
	preprocess();
	process(0);
	
}

void multiTest() {
	
	int t;
	cin >> t;
	
	for (int it = 1; it <= t; ++it) {
		input();
		preprocess();
		process(it);
	}
}

int main(){
    #ifndef ONLINE_JUDGE
//    freopen("../out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	oneTest();
//	multiTest();

    return 0;

}


Measured memory_bytes: 640
def main(R, G, B, N):
    R, G, B = sorted((R, G, B))
    n = 0
    for b in range(N // B + 1):
        xb = N - b * B
        for g in range(xb // G + 1):
            xg = xb - g * G
            if xg % R == 0:
                n += 1   
    return n

print(main(*map(int, input().split())))


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
 
int main(){
    int n,x;
    int counter;
     
    while(true){
        cin >> n >> x;
        counter = 0;
        if(n==0&&x==0)break;
        for(int i=1;i<=n-2;i++){
            for(int j=i+1;j<=n-1;j++){
                for(int k=j+1;k<=n;k++){
                    if(i+j+k==x)counter += 1;
                }
            }
        }
        cout << counter <<endl;
    }
 
}

Measured memory_bytes: 3040
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''


def main():
    S, T = list(map(str, input().split()))
    A, B = list(map(int, input().split()))
    U = input()

    if U == S:
        print(A-1, B)
    else:
        print(A, B-1)

if __name__ == '__main__':
    main()


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

int main(){
    string str;
    int que;
    cin >> str >> que;

    int rt = 0;
    string front = "";
    string back = "";
    for(int i=1; i<=que; i++){
        int ti;
        cin >> ti;
        if(ti == 1){
            rt++;
            rt%=2;
            continue;
        }
        int fi;
        char ci;
        cin >> fi >> ci;

        if((rt+fi-1)%2 == 0){
            front.push_back(ci);
        }else{
            back.push_back(ci);
        }
    }

    if(rt == 0){
        int len = front.length();
        for(int i=len-1; i>=0; i--) cout << front[i];
        cout << str + back << endl;
    }else{
        int len = back.length();
        for(int i=len-1; i>=0; i--) cout << back[i];
        len = str.length();
        for(int i=len-1; i>=0; i--) cout << str[i];
        cout << front << endl;
    }

    return 0;
}

Measured memory_bytes: 1216
#include<iostream>
using namespace std;
int main()
{
	long long a,b,sum=0,sub=0;
	char x;
	cin>>a>>x>>b;
     if(x=='+')
		{
		sum=a+b;
		cout<<sum;}
	 else
	   {
	   sub= a-b;
	   cout<<sub;
}
		return 0;	
}

Measured memory_bytes: 256
//fifer a tak luboin
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <unordered_map>
#include <map>
#include <set>
 
#define ll long long
#define mp make_pair
#define pb push_back
#define s second
#define f first
#define endl "\n"
 
using namespace std; 
 
const ll inf = 1e14;
const int mod = 998244353;
const int N = (int)100100;
const double eps = 1e-10;                                     
const double pi = acos(-1.0);
int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

pair <int, int> a[N];
int main() { 
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 
    //freopen("bacon.in", "r", stdin);
    //freopen("bacon.out", "w", stdout);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i].f;
        a[i].s = i;
    }

    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++) {
        cout << a[i].s << " ";
    }
    return 0;    
}


Measured memory_bytes: 1664
#include <stdio.h>
int main()
{
int h,w,i;
while(1){
scanf("%d", &h);
scanf("%d", &w);
if (h==0&&w==0){
break;
} else {
while(h>0){
for (i=0;i<w;i++) {
printf("#");
}
printf("\n");
h--;
}
printf("\n");
}
}
return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h> 
 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const LL INF=1e9;

int main(){
    LL N,K;
    cin>>N>>K;
    if(K==0){
        cout<<N*N<<endl;
        return 0;
    }
    LL tmp=0;
    LL sum=0;
    for(LL b=K+1;b<=N;b++){
        tmp=N/b*(b-K);
        if(N%b>=K-1){
            tmp+=(N%b-K+1);
        }
        //cout<<b<<" "<<tmp<<endl;
        sum+=tmp;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
L = list(map(int,input().split()))
L.append(0)
cur = L[0]
fugou = '±'
for i in range(1,N):
  if L[i] > cur:
    if not i == N:
      fugou = '+'
      break
  elif L[i] < cur:
    if not i == N:
      fugou = '-'
      break
if fugou == '±':
  print(1)
else:
  ans = 0
  for i in range(N):
    if fugou == '+':
      if cur > L[i]:
        fugou = '±'
        ans += 1
    elif fugou == '-':
      if cur < L[i]:
        fugou = '±'
        ans += 1
    else:
      if cur < L[i]:
        fugou = '+'
      elif cur > L[i]:
        fugou = '-'
    cur = L[i]
  print(ans+1)

Measured memory_bytes: 14480
#include <iostream>
#include <vector>
using namespace std;
const int INF = (1e9);
int main(){
  int N, Ma, Mb;
  cin >> N >> Ma >> Mb;
  vector< vector<int> > DP(410,vector<int>(410,INF));
  DP[0][0] = 0;
  for(int i = 0; i < N; ++i){
    vector< vector<int> > DP_ = DP;
    int a, b, c;
    cin >> a >> b >> c;
    for(int i = 0; i < 410; ++i){
      for(int j = 0; j < 410; ++j){
        if(DP[i][j] == INF) continue;
        DP_[i+a][j+b] = min(DP_[i+a][j+b], DP[i][j] + c);
      }
    }
    DP = DP_;
  }
  int ans = INF, t = 1;
  while(Ma*t < 410 && Mb*t < 410){
    ans = min(ans,DP[Ma*t][Mb*t]);
    ++t;
  }
  if(ans >= INF) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1640
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long n, i, j, k, ans, x, s;
	cin >> n;
	vector<long long> a(n), b(n);
	for (i = 0; i < n; i++) cin >> a[i] >> b[i]; 
	ans = 0; s = 0; 
	for (i = n - 1; i >= 0; i--) {
		x = (a[i] + s) % b[i];
		if (x > 0) {
			x = b[i] - x;
			s += x;
			ans += x;
		}
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)

using namespace std;

const int N=111;
int n,m,a[N][N],cnt;

int main(){
	scanf("%d",&n);
	rep (i,1,n) rep (j,1,i-1) a[i][j]=1;
	m=n+!(n&1);
	rep (i,1,n) a[i][m-i]=0;
	rep (i,1,n) rep (j,1,i-1) cnt+=a[i][j];
	printf("%d\n",cnt);
	rep (i,1,n) rep (j,1,i-1) if (a[i][j]) printf("%d %d\n",i,j);
	return 0;
}

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

using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

vector<ll> cnt,used;
vector<vector<ll>> G;
void dfs(ll root, ll num){
    used[root]=1;
    cnt[root]+=num;
    for(ll i=0;i<G[root].size();i++){
        if(used[G[root][i]]==0)dfs(G[root][i], cnt[root]);
    }
    return;
}

int main() {
    ll n, m, i, j, k;
    ll q;
    cin >> n >> q;
    cnt.resize(n+1);
    used.resize(n+1);
    for(i=0;i<=n;i++){
        cnt[i]=used[i]=0;
    }
    G.resize(n+1);
    for(i=0;i<n-1;i++){
        ll a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(i=0;i<q;i++){
        ll p,x;
        cin >> p >> x;
        cnt[p]+=x;
    }
    dfs(1LL, 0LL);
    for(i=0;i<n;i++){
        cout << cnt[i+1] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 22656
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<string > vecstr;
int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  cout << ((a <= c && c <= b)?"Yes":"No") << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

vector<string> split(string s,char ch){
	vector<string> ret;
	string tmp ="";
	rep(i,s.size()){
		if(s[i]==ch){
			ret.pb(tmp);
			tmp = "";
		}else tmp+=s[i];
	}
	if(tmp.size())ret.pb(tmp);
	return ret;
}

int main(){
	int n;
	while(cin>>n&&n){
		cin.ignore();
		map<string,int> mp;
		rep(i,n){
			string s;
			getline(cin,s);
			vector<string> vs = split(s,' ');
			rep(j,vs.size()){
				mp[vs[j]]++;
			}
		}
		char ch;
		cin>>ch;
		
		vector<pair<int,string>> vs;
		for(auto &e:mp){
			string s;
			int times;
			tie(s,times) = e;
			
			if(s[0]==ch) vs.pb(make_pair(-times,s));
		}
		sort(all(vs));
		if(vs.size()==0)cout<<"NA";
		rep(i,vs.size()){
			if(i)cout<<" ";
			cout<<vs[i].second;
			if(i==4)break;
		}
		cout<<endl;
	}
}

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ProblemB_CountingOfTrees solver = new ProblemB_CountingOfTrees();
        solver.solve(1, in, out);
        out.close();
    }

    static class ProblemB_CountingOfTrees {
        final int MOD = 998244353;

        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            int[] d = new int[n];

            int maxD = 0;
            for (int i = 0; i < n; i++) {
                d[i] = in.nextInt();
                ++a[d[i]];
                maxD = Math.max(maxD, d[i]);
            }

            long ans = 1;
            if (d[0] != 0 || a[0] != 1) {
                ans = 0;
            }
            for (int i = 1; i <= maxD; i++) {
                ans = ans * pow(a[i - 1], a[i]) % MOD;
            }
            out.println(ans);
        }

        private int pow(long a, long n) {
            long r = 1;
            while (n > 0) {
                if (n % 2 == 1) {
                    r = r * a % MOD;
                }
                a = a * a % MOD;
                n /= 2;
            }
            return (int) r;
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

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

    }
}



Measured memory_bytes: 34156
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
ll a[3010];

ll dp[3010][3010];

ll calc(int l, int r, ll rem) {
    if (l > r) return 0;
    if (dp[l][r] < 0) {
        ll L = rem - calc(l+1, r, rem-a[l]);
        ll R = rem - calc(l, r-1, rem-a[r]);
        dp[l][r] = max(L, R);
    }
    return dp[l][r];
}

ll solve() {
    ll sum = 0;
    for (int i = 0; i < n; i++) sum += a[i];
    memset(dp, -1, sizeof(dp));
    ll X = calc(0, n-1, sum);
    ll Y = sum - X;
    return X - Y;
}

void input() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 71296
#include<bits/stdc++.h>
using namespace std;
void fl()
{
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
int main()
{
	ios::sync_with_stdio(0);
//    fl();
	int n;
	cin>>n;
	string ss;
	cin>>ss;
	int cnt=0;
	for(int i=0;i<=(int)ss.length()-3;i++)
		cnt+=(int)(ss.substr(i,3)=="ABC");
	cout<<cnt<<endl; 
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

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

const LL INF=1<<30;
const LL MOD=1000000007;

LL gcd(LL a,LL b){
    if(b==0)return a;

    return gcd(b,a%b);
}


int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if((2*b+c)%4==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

#define clear(x) memset(x, 0, sizeof(x))
#define op(x) ((x) <= n ? (x) + n : (x) - n)
// op可以求出一个点x的对立点
#define mid ((l + r) / 2)
#define ls now * 2
#define rs now * 2 + 1

const int N = 4e4 + 10, M = N * 20;

int hd[N * 5], nxt[M], t[M], ec;
void addEdge(int u, int v)
{
	t[++ec] = v;
	nxt[ec] = hd[u];
	hd[u] = ec;
}
struct Flag {
	int pos, id;
	bool operator<(const Flag& f) const {
		return pos < f.pos;
	}
	Flag(int pos = 0): pos(pos) {}
} flgs[N * 2];

int n;
int cnt;
int id[N * 5];

void build(int now, int l, int r)
{
	id[now] = ++cnt;
	if (l == r) {
		addEdge(id[now], op(flgs[l].id));
		// 由“占位符”向真实点的对立点连边
		return;
	}
	build(ls, l, mid);
	build(rs, mid + 1, r);
	addEdge(id[now], id[ls]);
	addEdge(id[now], id[rs]);
	// 由父亲向儿子连边
}

void link(int now, int l, int r, int x, int y, int point)
{
	// 由point向区间[x,y]连边
	if (y < x) return;
	if (l == x && y == r) addEdge(point, id[now]);
	else if (y <= mid) link(ls, l, mid, x, y, point);
	else if(x > mid) link(rs, mid + 1, r, x, y, point);
	else link(ls, l, mid, x, mid, point), link(rs, mid + 1, r, mid + 1, y, point);
}

#undef mid

int dfn[N * 5], low[N * 5], tim;
int stk[N * 5], tp;
int scc[N * 5], sc;
bool in[N * 5];

void dfs(int u)   // Tarjan算法 强连通分量
{
	in[u] = 1;
	dfn[u] = low[u] = ++tim;
	stk[++tp] = u;
	int v;
	for (int i = hd[u]; i; i = nxt[i]) {
		if (!dfn[v = t[i]]) dfs(v), low[u] = min(low[u], low[v]);
		else if (in[v]) low[u] = min(low[u], dfn[v]);
	}
	if (dfn[u] == low[u]) {
		++sc;
		do {
			scc[v = stk[tp--]] = sc;
			in[v] = 0;
		} while (v != u);
	}
}

bool check(int v)
{
	tp = tim = ec = 0;
	clear(hd), clear(dfn), clear(low);
	build(1, 1, cnt = 2 * n);
	int l, r;
	for (int i = 1; i <= 2 * n; i++) {
		l = upper_bound(flgs + 1, flgs + 1 + 2 * n, Flag(flgs[i].pos - v)) - flgs;
		r = upper_bound(flgs + 1, flgs + 1 + 2 * n, Flag(flgs[i].pos + v - 1)) - flgs - 1;
		link(1, 1, 2 * n, l, i - 1, flgs[i].id), link(1, 1, 2 * n, i + 1, r, flgs[i].id);
	}
	for (int i = 1; i <= 2 * n; i++) if (!dfn[i]) dfs(i);
	for (int i = 1; i <= n; i++) if(scc[i] == scc[i + n]) return 0;
	// 判断x与y是否在同一个强连通分量内
	return 1;
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d%d", &flgs[i].pos, &flgs[i + n].pos);
		flgs[i].id = i, flgs[i + n].id = i + n;
	}

	sort(flgs + 1, flgs + n * 2 + 1);

	int l = 0, r = flgs[2 * n].pos - flgs[1].pos + 1, mid, ans;
	while (l <= r) { // 二分
		mid = (l + r) / 2;
		if (check(mid)) l = mid + 1, ans = mid;
		else r = mid - 1;
	}

	printf("%d", ans);
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



multimap<string,int> MAP;

int main(){

	int num_query;
	scanf("%d",&num_query);

	int command,x;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d",&command);

		string key;

		if(command == 0){

			cin >> key >> x;
			MAP.insert(make_pair(key,x));

		}else if(command == 1){

			cin >> key;
			auto at = MAP.lower_bound(key);

			while(at != MAP.end() && at->first == key){

				printf("%d\n",at->second);
				at++;
			}

		}else if(command == 2){

			cin >> key;
			MAP.erase(key);

		}else{ //command == 3

			string L,R;

			cin >> L >> R;

			auto at_L = MAP.lower_bound(L);
			auto at_R = MAP.upper_bound(R);

			while(at_L != at_R){

				printf("%s %d\n",at_L->first.c_str(),at_L->second);
				at_L++;
			}
		}
	}

	return 0;
}



Measured memory_bytes: 24904
n,k=map(int,input().split())
a=list(map(int,input().split()))

dp=[0]*(k+1)

for i in range(1,k+1):
    x=1
    for j in range(n):
        if i-a[j]>=0:
            x *= dp[i-a[j]]
    if x==1:
        dp[i]=0
    else:
        dp[i]=1
if dp[k]==1:
    print("First")
else:
    print("Second")

Measured memory_bytes: 42348
import java.util.Scanner;

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

        long x = stdIn.nextLong();

        long fromX = x / 500;

        long fromY = (x - fromX * 500) / 5;

        System.out.println(fromX * 1000 + fromY * 5);
    }
}

Measured memory_bytes: 23636
// Author: Wenxing Mei
//   File: c.cpp
//   Date: 2019-03-11 22:49
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define per(i, b, a) for (int i = (int)b; i >= (int)a; --i)
#define repv(ele, cont) for (auto &ele : cont)
#define all(x) x.begin(), x.end()
#define mp make_pair
#define eb emplace_back
#define ep emplace
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<ll> vll;
// END OF TEMPLATE

int main() {
#ifndef LOCAL
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#endif
    string s;
    cin >> s;
    vi stk;
    int re = 0;
    repv(c, s) {
        if (stk.empty())
            stk.eb(c);
        else if (stk.back() != c) {
            stk.pop_back();
            re += 2;
        } else
            stk.emplace_back(c);
    }
    cout << re << endl;
    return 0;
}


Measured memory_bytes: 972
def m():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    A.sort()
    tmp = -1
    cnt = 0
    ans = 0
    for i in range(N):
        if tmp == A[i]:
            cnt +=1
        else:
            if cnt % 2 == 0: pass
            else: ans +=1
            tmp = A[i]
            cnt = 1

    if cnt % 2 == 0: pass
    else: ans += 1
    return ans

print(m())


Measured memory_bytes: 7444
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def invmod(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m


n, k = map(int, input().split())
k_ = k - 1
a = sorted([int(i) for i in input().split(" ")])
c = 10**9 + 7

comb = [1 for i in range(n-k_)]
for i in range(1, n-k_):
    comb[i] = comb[i-1] * (k_+i) * invmod(i, c) % c
ans = 0
for i in range(k_, n):       
        ans += a[i]*comb[i-k_] % c
        #print("comb_temp", comb[i-2-j-k_], tmp)
        #print("ans", ans)
for i in range(n-k+1):
    ans -= a[i]*comb[n-k-i]
    ans = ans % c
print(ans)

Measured memory_bytes: 14416
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
string a,b;
int main()
{
    cin >> a;b=a;
    reverse(a.begin(),a.end());
    for(unsigned i=0;i<a.size();i++)
    {
        if(a[i]=='b') a[i]='d';
        else if(a[i]=='d') a[i]='b';
        else if(a[i]=='p') a[i]='q';
        else if(a[i]=='q') a[i]='p';
    }
    bool(a==b)?cout << "Yes\n":cout << "No\n";
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  int n;
  cin>>n;
  vector<int> l(n);
  rep(i,n)cin>>l[i];
  int ans = 0;
  rep(i,n){
    for(int j = i+1;j < n;j++){
      if(l[i] == l[j])continue;
      for(int k = j+1;k < n;k++){
        if(l[j] == l[k] || l[i] == l[k])continue;
        int sum = l[i]+l[j]+l[k];
        int m = max(l[i],max(l[j],l[k]));
        if(sum - m > m){
          ans++;
        }
      }
    }
  }
  print(ans);
  return 0;
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){

    int n;
    cin >> n;
    double x[n], y[n];
    VI v;
    rep(i,n) v.push_back(i);
    rep(i,n){
        cin >> x[i] >> y[i];
    }
    double sum = 0;
    double cnt = 0;
    do{
        rep(j,n-1){
            int idx = v[j];
            int idx2 = v[j+1];
            sum += sqrt( pow(x[idx2]-x[idx],2) + pow(y[idx2]-y[idx],2) );
        }
        cnt++;
    }while (next_permutation(all(v)));
    printf("%0.10lf\n",sum/cnt);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
        int h,w;
        while(true){
                cin >> h >> w;
                if(h+w==0)
                        break;
                for(int i=0 ; i<h ; i++ ){
                        for(int j=0 ; j<w ; j++ ){
                                if(i==0 || j==0 || i==h-1 || j==w-1 )
                                        cout <<"#";
                                else
                                        cout <<".";
                        }
                        cout << endl;
                }
                cout << endl;
        }
        return 0;
}

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

int main()
{
  long long NUM = 1000000007;
  int n, m;
  cin >> n >> m;
  vector<int> stairs(n + 1, -1);
  stairs.at(0) = 1;
  for (int i = 0; i < m; i++)
  {
    int a;
    cin >> a;
    stairs.at(a) = 0;
  }
  for (int i = 1; i <= n; i++)
  {
    if (stairs.at(i) == 0)
      continue;
    if (i == 1)
    {
      stairs.at(i) = stairs.at(i - 1);
    }else{
      stairs.at(i) = stairs.at(i - 1) + stairs.at(i - 2);
    }
    stairs.at(i) %= NUM;
  }
  cout << stairs.at(n) << endl;
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
 
int main(){
  bool r[100000];
  int h[100000],a[100000],b[100000],n,m;
  cin>>n>>m;
  for(int i = 0;i<n;i++){
	cin>>h[i];
    r[i] = true;
  }
  for(int i = 0;i<m;i++){
	cin>>a[i]>>b[i];
  }
  
  for(int i = 0;i<m;i++){
    auto dif = h[a[i] -1] - h[b[i]-1];
    if(dif > 0){
      r[b[i]-1] = false;
    }else if(dif<0){
		r[a[i]-1] = false;
    }else {
		r[a[i]-1] = false;
      r[b[i]-1] = false;
    }
  }
  int cnt = 0;
  for(int i = 0;i<n;i++){
    if(r[i]){
      cnt++;
    }
  }
  
  cout<<cnt<<endl;
  }

Measured memory_bytes: 4892
N,K=map(int, input().split()) 

def change(N,shinsu):
    keta=0
    for i in range(10**9):
        if N<shinsu**i:
             keta+=i
             break
    ans=[0]*keta
    check=0
    for i in range(1,keta+1):
        j=N//(shinsu**(keta-i))
        ans[check]=j
        check+=1
        N-=(j)*(shinsu**(keta-i))
    return ans

print(len(change(N,K)))

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

int main(){
	int n;
	std::cin >> n;

	std::vector<int> a(n);
	long long road[n-1][21] = {};

	for(int i = 0; i < n; ++i){
		std::cin >> a[i];
	}

	road[0][a[0]] = 1;

	for(int i = 0; i < n-2; ++i){
		for(int j = 0; j < 21; ++j){
			if(j + a[i+1] <= 20){
				road[i+1][j + a[i+1]] += road[i][j];
			}
			if(j - a[i+1] >= 0){
				road[i+1][j - a[i+1]] += road[i][j];
			}
		}
	}
	std::cout << road[n-2][a[n-1]] << std::endl;

	return 0;
}


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

int main(){
	int a;
	int b;
	int c;
	cin>>a;
	cin>>b;
	cin>>c;
	string rec;
	if((a<b)&&(b<c)){
		rec="Yes";
	}else{
		rec="No";
	}

	std::cout<<rec<<endl;
}





Measured memory_bytes: 3176
xx,k,d = list(map(int, input().split(' ')))
x = abs(xx) 

# case0: 絶対値を超える範囲まで届かない場合
if x >= k*d:
    print (x - k*d)
# case1: 絶対値を超える範囲に届く場合: 0の両隣のどちらかを選択
else:
    #wall = (x // d) + 1 # 0を超えるのに必要な移動回数
    #print("wall=",wall)
    #if wall % 2 == 0: # Xが偶数時: どちらも選択可能
    #    print (abs(x - wall*d))
    #else: # Xが奇数時: どちらかのみとなるので注意
    #    print (abs(x - (wall-1)*d))

    div = x//d

    a1 = abs(x - div*d)
    a2 = abs(x - (div+1)*d)
#    print(f"a1={a1}, a2={a2}")
    if (div % 2) != (k % 2):
        print (a2)
    else:
        print (a1)


Measured memory_bytes: 61852
n = int(input())
ans = 0


def divisors(n):
    set_div = set()
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            set_div.add(i)
            set_div.add(n//i)
    return set_div


for i in range(1, n+1, 2):
    t = len(divisors(i))
    if t == 8:
        ans += 1
print(ans)


Measured memory_bytes: 9440
#include<stdio.h>
#include<stdlib.h>

int p(int i){return i/2;}
int l(int i){return 2*i;}
int r(int i){return 2*i+1;}

int main(){
  int n,i,*A;

  scanf("%d",&n);
  A=(int *)malloc((n+1)*sizeof(int));
  for(i=1;i<=n;i++) scanf("%d",&A[i]);

  for(i=1;i<=n;i++){
    printf("node %d: key = %d",i,A[i]);
    if(p(i)>=1) printf(", parent key = %d",A[p(i)]);
    if(l(i)<=n) printf(", left key = %d",A[l(i)]);
    if(r(i)<=n) printf(", right key = %d",A[r(i)]);
    printf(", \n");
  }
  return 0;
}



Measured memory_bytes: 2044
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
int n;
vector<int> a;
vector< map<int, long long> > dp;
long long ref(int i, int k){
    auto itr = dp[i].find(k);
    if(itr == dp[i].end()) return -1e18;
    return itr->second;
}
int main(void){
    cin >> n;
    a.assign(n+1, 0);
    for(int i=1;i<=n;i++) cin >> a[i];
    dp.assign(n+1, map<int, long long>());
    dp[0][0] = 0;
    dp[1][0] = 0;
    dp[1][1] = a[1];
    for(int i=2;i<=n;i++){
        for(int j=0;j<5;j++){
            int k = (i+1)/2-j;
            if(k < 0) continue;
            long long res = ref(i-1, k);
            int cnt = 0;
            for(int l=i-2;l>=0;l--){
                long long tmp = ref(l, k-1) + a[i];
                if(tmp > res) res = tmp;
                if(++cnt > 5) break;
            }
            dp[i][k] = res;
            // cout << i << " " << k << " " << res << endl;
        }
    }
    cout << dp[n][n/2] << endl;
}


Measured memory_bytes: 70736
N=int(input())
A=list(map(int,input().split()))
ans=1
c=1
for n in range(N):
    if A[n]==0:
        c=0
        break
if c!=0:
    for n in range(N):
        ans=ans*A[n]
        if ans>10**18:
            c=-1
            break
if c==-1:
    print(-1)
elif c==0:
    print(0)
else:
    print(ans)


Measured memory_bytes: 21692
#include<iostream>
using namespace std;
int main(){
    int a,b;
    cin >>a >> b;
    if(a==b){
        cout <<"a == b"<<endl;
        
    }else if(a>b){
        cout<<"a > b"<<endl;
        
    }else{
        cout<<"a < b"<<endl;
    }
}


Measured memory_bytes: 3116
# 先頭の最大と最後尾の最小を求める
card_num, gate_num = map(int, input().split())
lmax, rmin = map(int, input().split()) # 最初の入力がlの最大とrの最小
for i in range(1, gate_num):
    l, r = map(int, input().split())
    lmax = max(lmax, l) # lmaxにlmaxとlの大きい方
    rmin = min(rmin, r) # rminにrminとrの小さい方
print(max(0, rmin-lmax+1)) # 0かrmin-lmax+1の大きい方を出力

Measured memory_bytes: 9108
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define OP ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair<int, int> pii;
const int inf = int(1e9);
const int mod = inf + 7;
const double PI = acos(-1.0);
using namespace std;
const int N = 1e5 + 155;
template<typename T>
inline void read(T&x){
    x=0;int f=1;char ch = getchar();
    while(ch<'0' ||ch>'9'){ if(ch=='-')f=-1;ch=getchar(); }
    while(ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
    x*=f;
}
 
 
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) r = (r * a) % mod;
		a = (a * a) % mod;
		n >>= 1;
	}
	return r;
}

 
void solve(){
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	cout << min(k, n) * x + max(0, n - k) * y;
}

int main(){
    OP
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
	//cin >> t;
    for(int i = 1; i <= t; i++) {
        solve();
    }
    return 0;
}

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

int main(){
  string a,b;
  cin>>a>>b;
  bool shinji=true;
  for(int i=0;i<a.size();i++){
    if(a[i]!=b[i]){
      shinji=false;
      break;
    }
}
  if(shinji){
    if(b.size()-a.size()==1){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }else{
    cout<<"No"<<endl;
  }
}

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

int main() {
  int n,ans=0; cin>>n;
  vector<int> a(100005);
  for(int i=0; i<n; i++) {
    int x; cin>>x;
    a[x]++;
  }
  for(int i=0; i<a.size(); i++){
    ans = max(ans,a[i-1]+a[i]+a[i+1]);
  }
  cout<<ans;
}

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

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

int main(void) {
	int A,B,X;
    cin>>A>>B>>X;
	if (X >= A && A + B >= X)cout << "YES" << endl;
	else cout << "NO" << endl;

	
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
int C[300000];
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N) {
    int a, b;
    cin >> a >> b;
    C[a+b]++;
  }
  vector<int> ans;
  rep(i, 300000-1) {
    C[i+1] += C[i]/2;
    if (C[i]%2) ans.pb(i);
  }
  for (int x : ans) cout << x << " " << 0 << "\n";
  return 0;
}

Measured memory_bytes: 4388
#include <stdio.h>
 
int main(void)
{
    int x, n;
    int i,j,k;
    int count=0;
 
    while(1){
        scanf("%d %d", &n, &x);
        if(n==0 && x == 0)
            break;
        for(i=1; i<n-1; i++){
            for(j=i+1; j<n; j++){
                for(k=j+1; k<=n; k++){
                    if(i+j+k == x)
                        count++;
                }
            }
        }
        printf("%d\n", count);
        count =0;
    }
    return 0;
}

Measured memory_bytes: 2724
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


h1, m1, h2, m2, k = MI()
t = h2 * 60 + m2
s = h1 * 60 + m1
print(max(0, t-k-s))

Measured memory_bytes: 61712
///
// File:  alds1_2_c.cpp
// Author: ymiyamoto
//
// Created on Wed Oct  4 01:32:07 2017
//

#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;
static vector<pair<uint32_t, char>> array1;
static vector<pair<uint32_t, char>> array2;

static void bubble_sort()
{
  for (uint32_t i = 0; i < array1.size(); i++) {
    for (uint32_t j = array1.size() - 1; j > i; j--) {
      if (array1[j - 1].first > array1[j].first) {
        swap(array1[j - 1], array1[j]);
      }
    }
  }
}

static void selection_sort()
{
  for (uint32_t i = 0; i < array2.size(); i++) {
    uint32_t min_index = i;
    uint32_t min_val = array2[i].first;
    for (uint32_t j = i; j < array2.size(); j++) {
      if (array2[j].first < min_val) {
        min_index = j;
        min_val = array2[j].first;
      }
    }
    swap(array2[i], array2[min_index]);
  }
}

int32_t main()
{
  uint32_t N;
  cin >> N;
  for (uint32_t i = 0; i < N; i++) {
    char color;
    uint32_t num;
    cin >> color >> num;
    array1.push_back({num, color});
    array2.push_back({num, color});
  }

  bubble_sort();
  selection_sort();

  for (uint32_t i = 0; i < array1.size(); i++) {
    if (i != 0) cout << " ";
    cout << array1[i].second << array1[i].first;
  }

  cout << endl << "Stable" << endl;

  bool is_stable = true;
  for (uint32_t i = 0; i < array2.size(); i++) {
    if (i != 0) cout << " ";
    cout << array2[i].second << array2[i].first;

    if (array1[i].second != array2[i].second) {
      is_stable = false;
    }
  }

  if (is_stable) {
    cout << endl << "Stable" << endl;
  } else {
    cout << endl << "Not stable" << endl;
  }

  return 0;
}

Measured memory_bytes: 3120
s = sorted(list(input()))
t = sorted(list(input()), reverse=True)

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

end = False
for i in range(min(len_s, len_t)):
    if s[i] < t[i]:
        print("Yes")
        end = True
        break
    elif s[i] == t[i]:
        continue
    else:
        print("No")
        end = True
        break

if not end:
    if len_s < len_t:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 3064